Why does IndexOf fail when there is a backslash "\" in the string?
string tmpString = "acg2xs5d.dui";
string tmpString2 = @"c:\acg2xs5d.dui";
MessageBox.Show(tmpString.IndexOf(@tmpString2).ToString());
This returns -1; no matter what.
If I change tmpString2 to "acg2xs5d.dui" and remove the "c:\" it returns 0 as expected.
It seems that the "\" is causing it to give an incorrect result of "-1".
Why is this and how do I work around/trap for this?
you need just to use
tmpString2.IndexOf(@tmpString)
instead of
tmpString.IndexOf(@tmpString2)
all is right except of the order. "\" is not an escape character because you use "@" before your string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With