【发布时间】:2015-12-29 22:52:56
【问题描述】:
我试图弄清楚如何检查字符串是否包含特定的表情符号。比如看下面两个表情:
骑车人:http://unicode.org/emoji/charts/full-emoji-list.html#1f6b4
美国国旗:http://unicode.org/emoji/charts/full-emoji-list.html#1f1fa_1f1f8
骑自行车的人是U+1F6B4,美国国旗是U+1F1FA U+1F1F8。
但是,要检查的表情符号是在这样的数组中提供给我的,只有字符串中的数值:
var checkFor = new string[] {"1F6B4","1F1FA-1F1F8"};
如何将这些数组值转换为实际的 unicode 字符并检查字符串是否包含它们?
我可以为 Bicyclist 找到一些有用的东西,但对于美国国旗,我很难过。
对于自行车手,我正在执行以下操作:
const string comparisonStr = "..."; //some string containing text and emoji
var hexVal = Convert.ToInt32(checkFor[0], 16);
var strVal = Char.ConvertFromUtf32(hexVal);
//now I can successfully do the following check
var exists = comparisonStr.Contains(strVal);
但这不适用于美国国旗,因为有多个代码点。
【问题讨论】:
标签: c# unicode string-matching emoji double-byte