开发者

text to ascii in java [closed]

It's difficult to tell what 开发者_如何学编程is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

Hello i was wondering to convert text in java to ascii


To convert text to ASCII you can do

String text = "Hello World!";
byte[] ascii = text.getBytes("US-ASCII");


you mean smth like

String str;
int[] asciiCodes = new int[str.length()];

for (int i = 0; i < str.length(); i ++) {
  asciiCodes[i] = (int)str.charAt(i);
}

?


You question is not very clear, but I guess you may want to write text using an OutputStreamWriter created with the US-ASCII character set:

OutputStream out = new FileOutputStream("ascii-file.txt");
Writer writer = new OutputStreamWriter(out, "US-ASCII");
writer.write("A string with accents éèà");
writer.close();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜