|
-
February 11th, 2009, 01:10 AM
#1
Escape character problem
I have file urls stored in a database field. Urls are like this:
"\\Images\Sunset.jpg"
Where I retrieve it and store in tha string variable it becomes
"\\\\Images\\Sunset.jpg";
@ character can be used with strings like strval=@"\\Images";
But how do I use it with string variables or Database values? Other than using Replace("\\","\"), can anyone suggest a better solution?
-
February 11th, 2009, 01:59 AM
#2
Re: Escape character problem
I don't think by just reading into string the escape chars would get added, I suspect that it is stored in DB that way.
Regards,
Ramkrishna Pawar
-
February 11th, 2009, 03:03 AM
#3
Re: Escape character problem
 Originally Posted by shuvo
Where I retrieve it and store in tha string variable it becomes
"\\\\Images\\Sunset.jpg";
How are you checking for this.
If you just look at variable with debugger, it always escapes it (even if you originally used @ char). If you are watching this through debugger, content is ok.
Put variable into TextBox or something similar, and you will see it without escaping.
-
February 11th, 2009, 03:05 AM
#4
Re: Escape character problem
just because the string's value is
Code:
"\\\\Images\\Whatever"
When you're debugging, the printed value when you output it to the console or a textbox for example will still be
EDIT: D'oh, beaten to the punch!
It's not a bug, it's a feature!
-
February 13th, 2009, 02:45 AM
#5
Re: Escape character problem
Thanks to all of you for your input.I found out that url is still working with "\\\\", that is returned from the database. I just had to replace the last "\\" with a "/".Seriously .net should improves its handling of escape characters.
-
February 13th, 2009, 02:46 AM
#6
Re: Escape character problem
Having to replace a backslash with a forward slash has nothing to do with .NET escape characters though ...
It's not a bug, it's a feature!
-
February 13th, 2009, 03:26 AM
#7
Re: Escape character problem
@Foamy...Try replacing "\\" with "\".
-
February 13th, 2009, 03:51 AM
#8
Re: Escape character problem
I'm not sure what you mean... I single backslash will appear as "\\" in C# since it doubles as an escape character, so it needs to be escaped. Two backslashes will therefore appear as "\\\\".
This can be avoided by appending a @ to the front of the string like this:
Code:
string path = @"C:\Program Files\...";
It's not a bug, it's a feature!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|