我回答了這個question,有一個人在線程中評論說'*'和' - '不是MathSymbol。如果執行此C#都返回false:爲什麼*不被視爲MathSymbol?
char.IsSymbol('*'); //false
char.IsSymbol('-'); //false
根據msdn:
有效符號是 UnicodeCategory以下類別的成員:MathSymbol,CURRENCYSYMBOL,ModifierSymbol和 OtherSymbol。 Unicode標準的符號一個鬆散定義設置包括以下字符 :
我這樣做snippet看到所有的MathSymbols,我發現了星號,也沒有減號在那裏,很明顯。
int ctr = 0;
UnicodeCategory category = UnicodeCategory.MathSymbol;
for (ushort codePoint = 0; codePoint < ushort.MaxValue; codePoint++) {
Char ch = Convert.ToChar(codePoint);
if (CharUnicodeInfo.GetUnicodeCategory(ch) == category) {
if (ctr % 5 == 0)
Console.WriteLine();
Console.Write("{0} (U+{1:X4}) ", ch, codePoint);
ctr++;
}
}
Console.WriteLine();
Console.WriteLine("\n{0} characters are in the {1:G} category",
ctr, category);
我想知道爲什麼這2個符號不被認爲是MathSymbols?
[Unicode數學符號在此處列出](http://www.fileformat.info/info/unicode/category/Sm/list.htm)。除非明確說明(它不是),否則正常的ASCII字符'*'和'-''不在此範圍內。 – user2864740
這只是程序員的一個數學符號,而不是印刷工。設置類型的人具有非常高的標準:) –
因此,各種編程語言對數學運算符(例如用於乘法的星號)使用哪種語言並不重要。在這種情況下,「數學符號」就像你在高中數學作業中會發現的那樣。 –