我試圖處理到下面的字符:⨝(http://www.fileformat.info/info/unicode/char/2a1d/index.htm)string.Empty.StartsWith(((char)10781).ToString())總是返回true?
如果您檢查一個空字符串是否以該字符開頭,它總是返回true,這並沒有任何意義!這是爲什麼?
// visual studio 2008 hides lines that have this char literally (bug in visual studio?!?) so i wrote it's unicode instead.
char specialChar = (char)10781;
string specialString = specialChar.ToString();
// prints 1
Console.WriteLine(specialString.Length);
// prints 10781
Console.WriteLine((int)specialChar);
// prints false
Console.WriteLine(string.Empty.StartsWith("A"));
// both prints true WTF?!?
Console.WriteLine(string.Empty.StartsWith(specialString));
Console.WriteLine(string.Empty.StartsWith(((char)10781).ToString()));
文化敏感 - 默認比較看起來像是一個巨大的災難性的違反最小驚喜原則的違反。有沒有什麼經驗法則可以確定哪些方法需要StringComparison來獲得「正常」序數行爲,哪些方法不需要? – bobince 2009-12-12 14:25:23
@ bobince-你見過這個問題 - http:// stackoverflow。COM /問題/ 72696 /這 - 是 - 通常,最好使用的-stringcomparison-ordinalignorecase或 - stringcom – RichardOD 2009-12-12 15:12:54