Reputation: 785
In my website I am preparing an array using datagrid items in c#, which works fine, however when I have some text in the grid which has "
as value code automatically replaces it with "
i have tried to replace "
with "
as below, however its failing and replacing "
with \"
Array.Value += "|" + dgrFinal.Rows[i].Cells[1].Text.Replace
("amp;", "").Replace(""","\"")
is there any way i can replace "
with ".
Can anyone please help me in this.....come on guys you are expert.
Upvotes: 6
Views: 25808
Reputation: 4899
You can use HttpUtility
. Here is an example.
using System.Web;
...
string value1 = "<html>";
string value2 = HttpUtility.HtmlDecode(value1);
string value3 = HttpUtility.HtmlEncode(value2);
Debug.WriteLine(value1);
Debug.WriteLine(value2);
Debug.WriteLine(value3);
This is the ouput:
<html>
<html>
<html>
I took the example from here.
Upvotes: 13
Reputation: 41
Asp.net GridViewRow:
row.Cells[3].Text.Trim().Replace(""", @"""")
Before: "Gasket 22"" rubber ventlation pipes"
After: "Gasket 22"" rubber ventlation pipes"
Upvotes: 0
Reputation: 6425
Have you tried
.Replace(""", @"""")
Edit: outside of a GridView (I'm using LinqPad)
string xxx = "sd"fd";
Console.WriteLine(xxx.Replace(""", @""""));
returns:
sd"fd
If it's still appearing as \" then the battle is with the gridView - I haven't used one for ages but I'd be tempted to try and get the data right before binding to the grid, rather than looping through the rows and cells afterwards.
Edit2: I was going to say it could be the the debugger escaping the quotes but I'm days behind on this one. Good spot @Rawling. At least it's now solved :)
Upvotes: 7