Geekpedia Forums Logo

C# problem. Replacing \

by joe sparshott on Thursday, November 29th - 9:32 AM



been trying for ages to get it to recognize it as a character and not a function.
here is the code i have at the moment:

string a;
a = textBox2.Text;
a = Regex.Replace("\", "/");

but it dosent end the String at the quotation marks.
this is what it takes the string as:
"\", "
it totally ignoes the \ and the second "
any advice. thanks.

Try this:

a = Regex.Replace(@"\", "/");

Or the old double slash technique:

a = Regex.Replace(@"\\", "/");

I used the same Regex.Replace but it didn't work  directly. I think you want to replace the file path character "\" to "/". If yes then this will help you

String strFilePath;

strFilePath = Regex.Replace(str,@\\,"/");

 

I used the same Regex.Replace but it didn't work  directly. I think you want to replace the file path character "\" to "/". If yes then this will help you

String strFilePath;

strFilePath = Regex.Replace(strFilePath,@"\\");","/

I think there is some problem in editor, so last two postings are wrong one

I used the same Regex.Replace but it didn't work  directly. I think you want to replace the file path character "\" to "/". If yes then this will help you

String strFilePath;

strFilePath = Regex.Replace(str,@"\\","/");