Link to home
Start Free TrialLog in
Avatar of Devsolutions
Devsolutions

asked on

replacing special charaters in c#

here is my problem.
I am adding a string in database and have some double quotes in that string
as  <a href="asdas" /> .Now whenever im fetching this from database every " double quotes get changed into \" so this becomes <a href =\"asads\"/> and i dont need these when i m using it in a page.
i tried using string.replace("\"",""") but its giving me an error regularly.
is there any other way i can replace those with that.

thanks
ruchi
Avatar of PHD
PHD

You don't have to palce a \.
you can double all your double quotes and place the @ before the string variable.

Something like this :

string my_field = @"<a href=""asdas"" />";

hope this help,
You can try to set HtmlEncode="False"  
Since the backslash is the escape character, you need to escape it in the replace. So:
string.replace("\\","")

That will replace all occurrances of the backslash with the empty string.
Avatar of Devsolutions

ASKER

HI PHD,
         I already tried using HTMLENCODE but that dint help me out.
sabeesh where shud i use htmlencode=false,
and JIm i wanted to replace \" so can i use it same way \\" is it? because maybe some other time if i need to use only \ it will replace that also with blank.

please help me with this
Hey jim its not happening,it doesnt take it that ways
Can you post the code?
Hello DevSolution,

Did you try the first solution I given with the @before the a string variable and setting all inner double quotes twice ?


string target =  Regex.Replace(str,  @"[^0-9]" ,"");

@"[^0-9]" change according to your use

using System.Text.RegularExpressions ;

Regards
Renju

ASKER CERTIFIED SOLUTION
Avatar of photowhiz
photowhiz
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial