Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C# replace command
Message
From
16/01/2008 11:27:09
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
OS:
Windows XP
Database:
MS SQL Server
Miscellaneous
Thread ID:
01282218
Message ID:
01282285
Views:
8
>>string x = "I'm a boy";
>>"I'm a boy"
>>x.Replace("'","\'")
>>"I'm a boy" && output - wrong
>
>See code below:
>
>string s = "I'm a man";
>MessageBox.Show(s, "before");
>s = s.Replace("'", @"\'");
>MessageBox.Show(s, "after");
>
>
>The '\' is the escape character in C languages and is a very special character. You can escape the escape character by adding another escape character (s = s.Replace("'", "\\'");) or by using the @ infront of the string.

Had to one up with with "I'm a man", huh? ;-)
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform