开发者

Is there an easier way to convert an int to unicode?

I'm currently doing a big switch statement in my javascript to convert

            case 176: char = '\u00B0'; break;
            case 177: char = '\u00B1'; break;
            case 178: char = '\u00B2'; break;
            case 179: char = '\u00B3'; break;
            case 180: char = '\u00B4'; bre开发者_JAVA百科ak;


if your variable is named intVar you could use ...

var stringVar = String.fromCharCode(intVar);

... to get the unicode character.


JavaScript uses UCS-2 internally.

Thus, String.fromCharCode(intVar) won’t work for supplementary Unicode characters. If intVar is 119558 (0x1D306, for the '

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜