Why does IndexOf Soft hyphen returns 0 as a string?

58 views Asked by At

If you call IndexOf with the soft hyphen character as parameter, it will work as expected:

"aaa".IndexOf(Convert.ToChar(173)) // return -1
"aaa\u00AD".IndexOf(Convert.ToChar(173)) // return 3

However, if you call the exact same code using the soft hyphen as a string, the returned value will be 0 even if there's no soft hyphen in the string.

"aaa".IndexOf(Convert.ToChar(173).ToString()) // return 0
"aaa\u00AD".IndexOf(Convert.ToChar(173).ToString()) // return 0

Why does the IndexOf fails when you use a string?

0

There are 0 answers