1

x is a string in any language/culture and want to find the last dot in the string:

int y = x.LastIndexOf(".");

Is the result (y) culture independent or not? Why?

rodins
  • 306
  • 2
  • 11
  • What culture-specific treatment are you expecting to encounter here? – madreflection Feb 24 '20 at 17:58
  • That was my thought. Isn't a period more or less a period everywhere? – Robert Harvey Feb 24 '20 at 17:59
  • There's no numeric or temporal parsing/formatting going on so interpretation in a culture-specific manner doesn't apply to this. – madreflection Feb 24 '20 at 17:59
  • Is c# find the last dot in all languages? Are there any culture which is not to recognize the dots? – rodins Feb 24 '20 at 18:05
  • 4
    CultureInfo is only relevant to culture-specific serialization like with dates and currency. A `.` is a `.` in a generic string anywhere on earth. Its only when a specific context is applied, for example `.` has a special meaning for numbers in certain cultures as a decimal separator, where other cultures don't use `.` for that and use `,` instead. But a string in and of itself is just a string. In this example its not applying any sort of meaning to `.`, just checking if it is there. So the string and the character are compared verbatim. – TheBatman Feb 24 '20 at 18:08

1 Answers1

2

LastIndexOf is culture insensitive. The value is matched if the unicode values of the characters are the same.

You can find more information on this in the Remarks section of Microsoft Docs.

In order to perform a culture-specific char search you'll have to make use of CompareInfo.LastIndexOf

slugster
  • 49,403
  • 14
  • 95
  • 145
Nathan
  • 1,303
  • 12
  • 26