如何在Java中使用变量与 (\u)?

huangapple go评论89阅读模式
英文:

How to use (\u) with Variable in Java

问题

You can use \u with a stored value in a variable like this:

你可以使用\u与存储在变量中的值一起使用,如下所示:

英文:

Can I use \u with Stored Value in a variable ?

I want to awesome icon in android

when I pass a static value to textview like this
textView.setText('\uf13b'); i will get awesome icon

but when I want to restore the string from database like this (\uf13b) or (f13b) I will get it as a string!

how can I convert it to character

如何在Java中使用变量与 (\u)?

If I store (\uf13b) as a string in database I will get it as a string

答案1

得分: 3

如果你在字符串中有F13B,你可以用以下方式将其转换为等效的Unicode字符:

char awesomeChar = (char) Integer.parseInt("f13b", 16);

输出是

请注意,这是一个私用区字符,你需要使用特殊的图标字体才能看到你期望的图标。

英文:

If you have F13B in a String, you can transform it into the equivalent Unicode character with:

char awesomeChar = (char) Integer.parseInt("f13b", 16)

Output is 

Note that this is a private use area character and you need to use a special icon font to see the icon you expect.

huangapple
  • 本文由 发表于 2020年8月11日 21:20:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63359028.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定