Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I want to replace '\' with '\\'.

I have written as below, but it gives an error as Unexpected character '\'.

Please help me.

newfilename = filename.Replace("\","\\");
Posted
Updated 13-Apr-11 21:36pm
v2
Comments
Tarun.K.S 14-Apr-11 2:50am    
I think you start voting and accepting the answer(s) that helped you.
Dalek Dave 14-Apr-11 3:37am    
Edited for Grammar and Readability.

newfilename = filename.Replace(@"\",@"\\");.
 
Share this answer
 
Comments
Dalek Dave 14-Apr-11 3:37am    
Yep, Spot on!
Sandeep Mewara 14-Apr-11 3:51am    
Yep! Correct.
Other possible way:
newfilename = filename.Replace("\\","\\\\");

Just escape '\' using the escapesequence '\'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900