简体   繁体   English

用Javascript查找Unicode字符名称

[英]Finding Unicode character name with Javascript

I need to find out the names for Unicode characters when the user enters the number for it. 用户输入数字时,我需要找出Unicode字符的名称。 An example would be to enter 0041 and get given "Latin Capital Letter A" as the result. 例如,输入0041并得到“拉丁大写字母A”作为结果。

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. 您可能可以解析UnicodeData.txt文件以获取此信息。

Here should be what you're looking for. 这应该是您要寻找的。 The first array is simply http://unicode.org/Public/UNIDATA/Index.txt with replacing newlines with | 第一个数组只是http://unicode.org/Public/UNIDATA/Index.txt ,用|代替换行符| ; ;

// 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. 您会注意到某些字符是重复的,因此您可能需要进行一些清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM