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
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
You can try to set HtmlEncode="False"
There a htmlencode method :
http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode(VS.71).aspx
http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.htmlencode(VS.71).aspx
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.
string.replace("\\","")
That will replace all occurrances of the backslash with the empty string.
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
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
ASKER
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 ?
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.RegularExpress
Regards
Renju
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks photowhiz can u please look into this problem as well
https://www.experts-exchange.com/questions/22708192/javascript-validation-of-user-controls-calender-and-texteditor-inside-detailsview.html
https://www.experts-exchange.com/questions/22708192/javascript-validation-of-user-controls-calender-and-texteditor-inside-detailsview.html
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,