• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 479
  • Last Modified:

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
0
Devsolutions
Asked:
Devsolutions
  • 3
  • 3
  • 2
  • +3
1 Solution
 
PHDCommented:
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,
0
 
sabeeshCommented:
You can try to set HtmlEncode="False"  
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
JimBrandleyCommented:
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.
0
 
DevsolutionsAuthor Commented:
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
0
 
DevsolutionsAuthor Commented:
Hey jim its not happening,it doesnt take it that ways
0
 
JimBrandleyCommented:
Can you post the code?
0
 
PHDCommented:
Hello DevSolution,

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


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

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

using System.Text.RegularExpressions ;

Regards
Renju

0
 
photowhizCommented:
Devsolutions, where are you seeing the "\"s? In the debugger? The IDE? These both display strings in C# format, with leading quotation marks and metacharacters (like quotes) escaped so they are syntactically valid C# strings. The characters are displayed this way so you can see nonprinting characters in strings and are not actually part of the strings. For example:

    System.Console.Writeline("one\t\"quote\"");

will print out as:

    one        "quote"
0
 
DevsolutionsAuthor Commented:
thanks photowhiz can u please look into this problem as well
http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22708192.html
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now