You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.Net 5: For Thai, IndexOf(string) returns wrong index for some strings #59120
[regression] [worked-in:.net core 3.1]
Using .NET 5 IndexOf(string) returns wrong index.
This is reproducible only for some input strings, when the culture is set to Thai.
Example:
CultureInfo.CurrentCulture = new CultureInfo("th");
var idxSeparator = "27".IndexOf("."); // returns 0 instead of -1
idxSeparator = "0".IndexOf("."); // returns -1 as expected
idxSeparator = "3".IndexOf("."); // returns -1 as expected
idxSeparator = "3345".IndexOf("."); // returns 0 instead of -1
Notes
in .netcore3.1 it returned -1 for all examples above (as I would expect)
In other languages this is not reproducible also in .Net 5
Indexof(char) does not have this problem
Original Comments
Feedback Bot on 9/7/2021, 01:21 AM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
Doing someString.IndexOf(".") using Thai culture should always return 0 regardless of contents of the someString. The reason is in Thai culture, the character . is sort ignorable character which is treated as if it doesn't exist at all. So, I am seeing the behavior you are getting is correct.
var idxSeparator = "27".IndexOf("."); // returns 0 instead of -1
idxSeparator = "3345".IndexOf("."); // returns 0 instead of -1
That is expected result as I mentioned before.
idxSeparator = "0".IndexOf("."); // returns -1 as expected
idxSeparator = "3".IndexOf("."); // returns -1 as expected
I am not getting this result using .NET 5.0 nor .NET 6.0. Are you sure th culture was set as current culture before calling IndexOf in such cases? Please try these cases one more time and confirm what you are getting.
in .netcore3.1 it returned -1 for all examples above (as I would expect)
That is because in net core 3.1 we were using Windows NLS and in .NET 5.0 we started using ICU instead. It is expected to see some differences because of that. You may review the doc for more info. Also, you can switch back to NLS behavior if you need to as the doc describe.
In other languages this is not reproducible also in .Net 5
This normal as different languages behave differently. Note, Thai language is special case when it comes to word breaking as this language doesn't use spaces between words. So, you can expect some such other behaviors you are seeing too.
Indexof(char) does not have this problem
That is expected too. When you search using character, the search will be performed as ordinal search operation and not as linguistic search. Which means Thai culture will not be used at all at that time. You can achieve the same result using string if you do something like
"0".IndexOf(".",StringComparison.Ordinal);
@GrabYourPitchforks please review my reply here just in case you need to update anything again in #43956.
@tarekgh I don't have anything to add to your reply. It is very well stated. :)
Given that OP referred to this behavior as a "problem" and called out the clear contrast with the ordinal routine IndexOf(char), I think my original assumption that they wanted an ordinal instead of a linguistic operation is correct. So I'll leave the 43956 link as-is pending any clarification from OP that they meant something different.
Activity
GrabYourPitchforks commentedon Sep 15, 2021
I added this to the big list at #43956.
maryamariyan commentedon Sep 16, 2021
It regressed in 5.0, would be good to also test in 6.0.
@GrabYourPitchforks @tarekgh is this something we'd need to look at in 6.0?
tarekgh commentedon Sep 20, 2021
Doing
someString.IndexOf(".")using Thai culture should always return0regardless of contents of thesomeString. The reason is inThaiculture, the character.is sort ignorable character which is treated as if it doesn't exist at all. So, I am seeing the behavior you are getting is correct.That is expected result as I mentioned before.
I am not getting this result using .NET 5.0 nor .NET 6.0. Are you sure
thculture was set as current culture before callingIndexOfin such cases? Please try these cases one more time and confirm what you are getting.That is because in net core 3.1 we were using Windows
NLSand in .NET 5.0 we started usingICUinstead. It is expected to see some differences because of that. You may review the doc for more info. Also, you can switch back toNLSbehavior if you need to as the doc describe.This normal as different languages behave differently. Note, Thai language is special case when it comes to word breaking as this language doesn't use spaces between words. So, you can expect some such other behaviors you are seeing too.
That is expected too. When you search using character, the search will be performed as ordinal search operation and not as linguistic search. Which means
Thaiculture will not be used at all at that time. You can achieve the same result using string if you do something like@GrabYourPitchforks please review my reply here just in case you need to update anything again in #43956.
GrabYourPitchforks commentedon Sep 20, 2021
@tarekgh I don't have anything to add to your reply. It is very well stated. :)
Given that OP referred to this behavior as a "problem" and called out the clear contrast with the ordinal routine
IndexOf(char), I think my original assumption that they wanted an ordinal instead of a linguistic operation is correct. So I'll leave the 43956 link as-is pending any clarification from OP that they meant something different.