I am confused with this code.
string str = sample.indexof("a",0);
It’s working. But below not working.
string str = sample.indexof("\",0);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to escape backslashes in string and character literals in C# – or use a verbatim string literal. Any of these will work:
Or without specifying the initial index, if you’re looking from the start anyway:
Personally I would use the last of these if you’re only looking for a single character – it’s clearer that it really is exactly one character. (It may be marginally more efficient too, but the clarity is more important.)
(Note that C# is case sensitive – it’s
IndexOf, notindexof. Also note that it returnsint, notstring. It helps if you can make your sample code accurate…)