runtime
runtime copied to clipboard
string IndexOf work differently for windows and linux
.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
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