runtime icon indicating copy to clipboard operation
runtime copied to clipboard

string IndexOf work differently for windows and linux

Open ichensky opened this issue 8 years ago • 1 comments

.net core 2.1

windows 10 x64: 
"some \n string".IndexOf("\n")        | result 5
"some \r\n string".IndexOf("\n")      | result 6
"some \r\n string".IndexOf('\n')      | result 6
"some \n string".IndexOf('\n')        | result 5

linux ubuntu x64: 
"some \n string".IndexOf("\n")        | result 5
"some \r\n string".IndexOf("\n")      |-> result -1
"some \r\n string".IndexOf('\n')      | result 6
"some \n string".IndexOf('\n')        | result 5

ichensky avatar Jul 16 '18 18:07 ichensky

We depend on the OS for linguistic string comparisons. so this behavior is expected. if you want to get the desired behavior you can use ordinal comparisons

public int IndexOf(string value, StringComparison comparisonType) 

and pass StringComparison.Ordinal to it

tarekgh avatar Jul 16 '18 19:07 tarekgh