开发者

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

开发者 https://www.devze.com 2023-03-08 20:08 出处:网络
I\'m currently doing a big switch statement in my javascript to convert case 176: char = \'\\u00B0\'; break;

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

精彩评论

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