I'm trying to get a Text description from a website and used this code
HttpResponseMessage response1 = await httpClient.GetAsync(url);
response1.EnsureSuccessStatusCode();
string srcCode = await response1.Content.ReadAsStringAsync();
string desc = "";
rem = @"id=""full_notes"">";
if (srcCode.IndexOf(rem) != -1)
{
desc = srcCode.Remove(0, srcCode.IndexOf(rem) + rem.Length);
rem = @"<a href=""#"">less</a></span>";
desc = desc.Remove(desc.IndexOf(rem));
}
else
{
rem = @"<span>Description:</span>";
desc = srcCode.Remove(0, srcCode.IndexOf(rem) + rem.Length+15);
rem = "</div>";
desc = desc.Remove(desc.IndexOf(rem));
}
string rep = @"""";
desc.Replace(""",rep);
on.Description = desc;
all goes well and I show it in a textblock but the problem comes when the text I get has quotes "" then the textblock would only show " instead of the " anyone knows how to fix this?
Note: I tried to use replace as shown in the code it didn't work
You're calling Replace
but not doing anything with the result - strings are immutable in C#, so the Replace
method doesn't change the contents of the existing string. As the documentation states:
This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of oldValue are replaced by newValue.
So you'd need:
desc = desc.Replace(""", "\"");
Fundamentally though, I think you'd be better off using an HTML parser (e.g. HTML Agility Pack). That should be able to perform this sort of entity replacement for you.
See more on this question at Stackoverflow