如果您将 Windows Phone 模拟器或设备设置为日语、韩语或其他非拉丁语并使用人脉应用程序,他们的 LongListSelector 实现会显示日语分组字符,然后是 unicode“globe with meridians”字符,后跟a-z 字符:
使用 Windows Phone 工具包中的 LongListSelector,您必须执行自己的手动分组逻辑。如何获取日语/韩语/等名称分组字符的列表以及如何确定名称所属的分组字符(自从查看我的第二张屏幕截图后,用户名中没有分组字符)?
最佳答案
简短的回答是:将 96 添加到平假名 (ま) 的 unicode 值以获得等效的片假名 (マ)。
您可以通过检查字符的 unicode 值是否在 3040-309F 范围内来确定字符是否为平假名。
不幸的是,正如 Noah 提到的那样,许多名字都是用汉字拼写的:一个大约有 40,000 个字符的字母表,每个字符都有对应的平假名,并且许多与周围环境相关。如果您想支持这些,您需要寻找日语图书馆来帮助您。
仅供引用,片假名偶尔用于表示大写字母,因此可以在此处解释它们的用法。 (考虑到 Metro 的小写偏好,我认为片假名更合适)。
如果你只想支持平假名,这里有一些东西应该对你有帮助:
const int KatakanaStartCode = 0x30A0;
const int HiraganaStartCode = 0x3040;
const int HiraganaEndCode = 0x309F;
private char GetGroupChar(string name)
{
// Check for null/blank
// Check for numbers, etc
char firstChar = name[0];
int firstCharCode = (int)firstChar;
bool isHiragana = (HiraganaStartCode <= firstCharCode &&
firstCharCode <= HiraganaEndCode);
if (isHiragana)
{
char katakanaChar = (char)(firstCharCode +
(KatakanaStartCode - HiraganaStartCode));
return katakanaChar;
}
return Char.ToLowerInvariant(firstChar);
}
然后:
string name = "またな たなかあ";
char s = GetGroupChar(name);
Debug.WriteLine(s); // マ
关于c# - 如何在 LongListSelector 中对日语和其他非拉丁语名称进行分组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9117597/