-1

I need to convert from this character;

"\\\\192.168.2.11\\MKRPRTAL-2.11\\TechnicalDocuments\\TechnicalDocumentsCore\\1000020200-test5_ED_R1.pdf"

to :

"192.168.2.11\\MKRPRTAL-2.11\TechnicalDocuments\TechnicalDocumentsCore\1000020200-test5_ED_R1.pdf"

I tried

rawPath = response2.TechDocSeriBilgiGetirList[0].PhysicalPathCore.Replace(@"\\", @"\").Replace(@"/", @"\");

(response2.TechDocSeriBilgiGetirList[0].PhysicalPathCore) is equals ;

"\\\\192.168.2.11\\MKRPRTAL-2.11\\TechnicalDocuments\\TechnicalDocumentsCore\\1000020200-test5_ED_R1.pdf"
fubo
  • 44,811
  • 17
  • 103
  • 137
try123
  • 15
  • 2
  • 1
    Does this answer your question? [Stop visual studio debug putting slash in string containing double quotes](https://stackoverflow.com/questions/41172620/stop-visual-studio-debug-putting-slash-in-string-containing-double-quotes) – NineBerry Apr 01 '21 at 11:36
  • 1
    How are you viewing your strings? In Visual Studio strings are displayed with delimited characters, so `\n` is a newline and `\t` is a tab and a backslash is displayed as `"\\"` so you might think you have twice as many as you want when you really don't. – juharr Apr 01 '21 at 11:37
  • See also https://stackoverflow.com/questions/61993958/strange-path-in-debug-is-with-double-backslash-but-on-the-message-small-magni – NineBerry Apr 01 '21 at 11:37

3 Answers3

2

You should take into account that the \ character is represented with \\ because the backslash is a special character. For example \n means a line break. Just like you've pressed the enter key on your keyboard.

try running this piece of code:

System.Console.WriteLine("I am in first line\nAnd i am in the next line");

the output will be:

I am in first line
And i am in the next line

The same thing applies to \\. try this:

System.Console.WriteLine("\\");

It will output only one backslash! (\)

My guess is you are looking at the value of your variable using Visual Studio debugger. Try printing them using the System.Console.WriteLine method. It will show you the "true value" of the variable.

Also can you please append the result of that line of code you posted?

OverShifted
  • 457
  • 1
  • 7
  • 17
1

String operations are immmutable. So to check the value you need to inspect rawPath after the operation and not string on which you perform those operations because that one does not change.

Check this link:

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/strings/#:~:text=String%20objects%20are%20immutable%3A%20they,in%20a%20new%20string%20object.

Philip Stuyck
  • 7,344
  • 3
  • 28
  • 39
1

Please try below code :

string strvar = @"\\\\192.168.2.11\\MKRPRTAL-2.11\\TechnicalDocuments\\TechnicalDocumentsCore\\1000020200-test5_ED_R1.pdf";        
string strrep = strvar.Replace(@"\\\\", @"").Replace(@"\\", @"\");

output will be :

192.168.2.11\MKRPRTAL-2.11\TechnicalDocuments\TechnicalDocumentsCore\1000020200-test5_ED_R1.pdf
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
  • I tried but it's not work. My value is : "\\\\192.168.2.11\\MKRPRTAL-2.11/TechnicalDocuments/TechnicalDocumentsCore/1000020200-test5_ED_R1.pdf" But I need to "\\192.168.2.11\MKRPRTAL-2.11\TechnicalDocuments\TechnicalDocumentsCore\1000020200-test5_ED_R1.pdf" – try123 Apr 01 '21 at 12:42