Cameron
Cameron

Reputation: 229

SQLDataReader returns string with additional break characters \\\\

I am using SQLDataReader in C# to query a SQL table. One of the fields in this table is a string that holds a file path, for example "C:\\Files\\MyFiles".

However, SQLDataReader returns this string with two additional backslashes. For example: "C:\\\\Files\\\\MyFiles".

SQLDataReader appears to be detecting the escape character "\". Is there anyway I can stop it doing this?

Upvotes: 2

Views: 666

Answers (2)

Imran Khan Hunzai
Imran Khan Hunzai

Reputation: 310

You can replace the \\\\ with \\.

Upvotes: 0

Zein Makki
Zein Makki

Reputation: 30042

It is somehow misleading for some developers when inspecting the value in visual studio. You get a string like this:

C:\\\\Files\\\\MyFiles

But when you print it to the console you get the exact string:

Console.WriteLine(path); /* C:\\Files\\MyFiles */

You can click the Magnifier icon to check the exact string characters. So no worries, you're safe to go it is just Visual Studio adding some escape characters.

Upvotes: 2

Related Questions