Finding Unicode character name with Javascript

耗尽温柔 提交于 2019-12-24 09:48:13

问题


I need to find out the names for Unicode characters when the user enters the number for it. An example would be to enter 0041 and get given "Latin Capital Letter A" as the result.


回答1:


As far as I know, there isn't a standard way to do this. You could probably parse the UnicodeData.txt file to get this information.




回答2:


Here should be what you're looking for. The first array is simply http://unicode.org/Public/UNIDATA/Index.txt with replacing newlines with |;

// this mess..
var unc = "A WITH ACUTE, LATIN CAPITAL LETTER   00C1| /*... really big array ...*/ |zwsp    200B";
var uncs=unc.split("|");
var final_a = [];
var final_s = "";
for each (var item in uncs) {
    var _T=item.split("\t");
    //final_a [_T[1]] = _T[0];
    final_s += '"' + _T[1] + '"' + ' : ' + '"' + _T[0] + '",';
}

console.log (final_s);

// yields..

var unicode_lookup = { /*really big array*/ }

// which we can use like so ...

alert(unicode_lookup["1D01"]);
// AE, LATIN LETTER SMALL CAPITAL

SO doesn't preserve tabs so the first part may not work if you simply copy-paste it. You'll note that some characters are duplicates so you may want to do some cleanup.



来源:https://stackoverflow.com/questions/44983646/how-can-i-get-the-official-unicode-name-of-a-character-in-javascript-from-either

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!