【发布时间】:2023-03-15 19:31:01
【问题描述】:
我有一个六位 unicode 字符,例如 U+100000,我希望与我的 C# 代码中的另一个 char 进行比较。
我对@987654321@ 的解读是,这个字符不能用char 表示,而必须用string 表示。
U+10000 到 U+10FFFF 范围内的 Unicode 字符不允许在字符文字中使用,而是在字符串文字中使用 Unicode 代理对表示
我觉得我遗漏了一些明显的东西,但是您如何才能使以下比较正常工作:
public bool IsCharLessThan(char myChar, string upperBound)
{
return myChar < upperBound; // will not compile as a char is not comparable to a string
}
Assert.IsTrue(AnExample('\u0066', "\u100000"));
Assert.IsFalse(AnExample("\u100000", "\u100000")); // again won't compile as this is a string and not a char
编辑
k,我想我需要两种方法,一种接受字符,另一种接受“大字符”,即字符串。所以:
public bool IsCharLessThan(char myChar, string upperBound)
{
return true; // every char is less than a BigChar
}
public bool IsCharLessThan(string myBigChar, string upperBound)
{
return string.Compare(myBigChar, upperBound) < 0;
}
Assert.IsTrue(AnExample('\u0066', "\u100000));
Assert.IsFalse(AnExample("\u100022", "\u100000"));
【问题讨论】:
标签: c# unicode unicode-escapes