My problem is that String.IndexOf returns -1 . I expect it to return 0 .
Options:
text = C:\\Users\\User\\Desktop\\Sync\\̼ (note the Seagull Combination symbol below )
stringToTrim = C:\\Users\\User\\Desktop\\Sync\\
When I check the index using int index = text.IndexOf(stringToTrim); , the value of index is -1 . I found that using ordinal string comparison helped solve this problem:
int index = text.IndexOf(stringToTrim, StringComparison.Ordinal);
Reading online, many Unicode characters (e.g. U + 00B5 and U + 03BC ) are mapped to the same character, so it would be nice to expand this and normalize both lines:
int index = text.Normalize(NormalizationForm.FormKD).IndexOf(stringToTrim.Normalize(NormalizationForm.FormKD), StringComparison.Ordinal);
Is this the right approach to check which index row contains all consecutive characters of another string? So, the idea is that you normalize when you want to check if the characters match, but you don’t normalize when you want to check the characters for their encoded values (say, duplicate characters)? Also, can someone explain why int index = text.IndexOf(stringToTrim); did not find a match at the beginning of the line? In other words, what is he really doing under the covers? I would expect it to start searching for characters from the beginning of the line to the end of the line.
string c # indexof unicode culture
Alexandru
source share