Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String.IndexOf broken for 'ʻ' #14691

Closed
faimada opened this issue Jun 10, 2015 · 2 comments
Closed

String.IndexOf broken for 'ʻ' #14691

faimada opened this issue Jun 10, 2015 · 2 comments
Assignees
Milestone

Comments

@faimada
Copy link

faimada commented Jun 10, 2015

var tmp = "aʻ";
Console.WriteLine( tmp.Contains("a") ); // True
Console.WriteLine( tmp.IndexOf("a") ); // -1

@ellismg
Copy link
Contributor

ellismg commented Jun 10, 2015

The problem here is Contains does an ordinal comparison, whereas IndexOf does a linguistic comparison. In this case, the second character (U+02BB, MODIFIER LETTER TURNED COMMA) modifies the previous letter such that the pair is treated differently from the raw letter a.

This happens with other characters as well, for example U+0303 (COMBINING TILDE).

If you change your sample to be:

var tmp = "aʻ";
Console.WriteLine(tmp.Contains("a")); // True
Console.WriteLine(tmp.IndexOf("a", StringComparison.Ordinal)); // 0

Then you get the behavior you expect, since now both functions are doing ordinal comparisons.

@stephentoub
Copy link
Member

@faimada, I'm going to close this out; please reopen if you still believe there's a problem. Thanks.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 1.0.0-rtm milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants