开发者

Convert a char to a String

I want to convert a char to a String开发者_如何转开发 in the following way:

char aaa = '\uE001';

I want to obtain a string with the value of "\uE001" so I can use substring(2) to obtain only "E001". Is that possible? Please help


Well, the character itself is a single character, U+E001. It has the hex value 0xE001. If you want that value as an integer, just use:

int unicodeValue = aaa;

You can then convert that integer value to hex in various ways, if you really need to, for example:

String hex = Integer.toString(unicodeValue, 16);

(That's assuming that overload is available on java-me.)

... or Integer.toHexString if that's available but Integer.toString(int, int) isn't.

Why do you want this value though? If you could clarify that, we may be able to give you more useful advice.


Integer.toHexString((int)aaa) ;

..and no substring() required.


This is the simple like that

char aaa = '\uE001';

String s=String.valueOf(aaa);


You can take any integer value and create a hex string from it like this:

  String s = Integer.toHexString(num);

so Jon Skeet is on the right track. You can:

  char aaa = '\uE001';
  int num = aaa;
  String hex = Integer.toHexString(num); //now contains "e001"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜