最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Finding Unicode character name with Javascript - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Jul 8, 2017 at 7:29 hippietrail 17k21 gold badges109 silver badges178 bronze badges asked Sep 26, 2010 at 16:53 TomCTomC 3211 gold badge3 silver badges5 bronze badges 2
  • You're going to have to construct (or appropriate) a lookup table. There's nothing built in to the language or browsers (or any server-side runtime I know of) that'll do this for you. – Pointy Commented Sep 26, 2010 at 17:00
  • Other solutions may involve using existing modules or web APIs. – hippietrail Commented Jul 8, 2017 at 7:27
Add a comment  | 

2 Answers 2

Reset to default 10

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.

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.

发布评论

评论列表(0)

  1. 暂无评论