"); ...">

How to replace a single character with a backslash using regex.replace in C #

If I do this:

Regex.Replace("unlocktheinbox.com", "[t]", "\\$&"); 

My result:

 "unlock\\theinbox.com" 

I expect it to be

 "unlock\theinbox.com" 

I am trying to replace "t" with "\ t" using regex.replace. I made this example very simple to explain what I'm trying to accomplish.

+5
source share
1 answer

Try to execute

 var result = Regex.Replace("unlocktheinbox.com", "[t]", @"\"); 

Please note that if you observe result during debugging with the mouse on result . it will look like unlock\\theinbox.com , because \ shielded. But in fact, if you type result or use anywhere, it will unlock\theinbox.com

+3
source

Source: https://habr.com/ru/post/1241901/


All Articles