Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Searching for backslash character in string in C#

I am strugling with getting the index of sequence "\a\b" in string. Any idea how to do it? I am doing following:

string expr = "Hello\a\b";
Console.WriteLine(expr.IndexOf("\a\b"));

This code returns 0 instead of expected 5

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

string expr = "Hello\a\b";
var inx = expr.IndexOf("\a\b", StringComparison.Ordinal);

Refer to documentation
https://learn.microsoft.com/en-us/dotnet/api/System.StringComparison?view=net-6.0

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading