I was fiddling around with parsing in C# and found that for every string I tried, string.StartsWith("\u2D2D")
will return true. Why is that?
It seems it works with every char. Tried this code with .Net 4.5 the Debugger did not break.
for (char i = char.MinValue; i < char.MaxValue; i++) { if(!i.ToString().StartsWith("\u2d2d")) { Debugger.Break(); } }
In C#, StartsWith() is a string method. This method is used to check whether the beginning of the current string instance matches with a specified string or not. If it matches then it returns the string otherwise false. Using foreach-loop, it is possible to check many strings.
The StartsWith method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search.
I think I'll have a try.
From what I get, is that U+2D2D was added in Unicode v6.1 (source / source).
The .NET framework, or the native calls rather, support a lower version:
The culture-sensitive sorting and casing rules used in string comparison depend on the version of the .NET Framework. In the .NET Framework 4.5 running on the Windows 8 operating system, sorting, casing, normalization, and Unicode character information conforms to the Unicode 6.0 standard. On other operating systems, it conforms to the Unicode 5.0 standard. (source)
Thus it is required to mark it as an ignorable character, which behaves just as if the character wasn't even there.
Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. (source)
Example:
var culture = new CultureInfo("en-US"); int result = culture.CompareInfo.Compare("", "\u2D2D", CompareOptions.None); Assert.AreEqual(0, result);
string.StartsWith
uses a similar implementation, but uses CompareInfo.IsPrefix(string, string, CompareOptions)
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With