Converting double slashes
-
appologies, I was trying to keep it simple. I'm actually calling the stored proc 'sp_attach_db' and I've tried command.CommandText.Replace("\\",@"\"); but it didnt do anything to the commandtext value.
That's not surprising, both literals end up as a single backslash. I suggest you post the actual problem you're encountering on the SQL/ADO/ADO.NET forum.
Stability. What an interesting concept. -- Chris Maunder
-
-
Martin# wrote:
filename.Replace("\\","\");
That won't even compile. What you intended to write was:
filename.Replace("\\\\","\\");
orfilename.Replace(@"\\",@"\");
However, that will not do anything at all, as the string doesn't contain any double backslashes.--- single minded; short sighted; long gone;
-
That's not surprising, both literals end up as a single backslash. I suggest you post the actual problem you're encountering on the SQL/ADO/ADO.NET forum.
Stability. What an interesting concept. -- Chris Maunder
-
appologies, I was trying to keep it simple. I'm actually calling the stored proc 'sp_attach_db' and I've tried command.CommandText.Replace("\\",@"\"); but it didnt do anything to the commandtext value.
Mark06 wrote:
I've tried command.CommandText.Replace("\\",@"\"); but it didnt do anything to the commandtext value.
Of course not. You are replacing each single backslash with a single backslash. Also, the Replace method doesn't change the string, it returns the new string, so you have to use the result of the method:
str = str.Replace("\\\\", "\\");
Still, the string literal that you showed doesn't contain any double backslashes, so that will not have any effect at all. What has made you come to the conclusion that the database has any problems with double backslashes, and why do you think that your string contains any?--- single minded; short sighted; long gone;
-
but this isnt an sql problem. the problem is, c# setting a commandtext to "sp_attach_db N'c:\\temp\\logfile.txt'" when it should be "sp_attach_db N'c:\temp\logfile.txt'" the actual sql command is irrelevant. its the double slashes thats the issue.
-
but this isnt an sql problem. the problem is, c# setting a commandtext to "sp_attach_db N'c:\\temp\\logfile.txt'" when it should be "sp_attach_db N'c:\temp\logfile.txt'" the actual sql command is irrelevant. its the double slashes thats the issue.
Visual Studio shows escapes in the C# debugger watch window and tooltips. I think that's a stupid idea, but there you are: that's what it does. If you output the string to the console (Console.WriteLine) you will see that the backslashes are not doubled. If you're having trouble attaching the database, please ask on the other forum (including all error messages) - this is not the problem.
Stability. What an interesting concept. -- Chris Maunder
-
Mark06 wrote:
the problem is, c# setting a commandtext to "sp_attach_db N'c:\\temp\\logfile.txt'" when it should be "sp_attach_db N'c:\temp\logfile.txt'"
It doesn't. Why do you think that it would?
--- single minded; short sighted; long gone;
Damn debugger watch window (and tooltips) shows it as doubled.
Stability. What an interesting concept. -- Chris Maunder
-
Damn debugger watch window (and tooltips) shows it as doubled.
Stability. What an interesting concept. -- Chris Maunder
-
Hi, Ive got a filename that i'm passing to an stored proc, but the string is a filename:
string filename = "c:\\temp\\LogFile.Txt";
my command is built:command.CommandText = "sp_UpdateLogFile '" + filename + "'";
however, sql doesnt accept the \\ directory seperators, they should only be one \. Is there a function already available to remove these double slashes?ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref2/html/M_System_String_Replace_1_d460c748.htm use filename.replace("\\","\")
-
Visual Studio shows escapes in the C# debugger watch window and tooltips. I think that's a stupid idea, but there you are: that's what it does. If you output the string to the console (Console.WriteLine) you will see that the backslashes are not doubled. If you're having trouble attaching the database, please ask on the other forum (including all error messages) - this is not the problem.
Stability. What an interesting concept. -- Chris Maunder
Never, never apply Console.WriteLine on a suspicious variable. You might find the cause of a problem...
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }