Pankaj Upadhyay
Pankaj Upadhyay

Reputation: 13594

Storing Html into a string in C#

In my project, I need to read some URLs and store the starting tags into some variables, but the project won't compile. May be, its because I am not using the assignment to the string correctly. Following is what i tried and got the compile error

string startTag = "<span id="productLayoutForm:OurPrice" class="pdp_details_hs18Price" itemprop="price">";

string anotherStartTag = "<span class="price final-price our fksk-our" id="fk-mprod-our-id">Rs.<span class="small-font">"

Please tell, what should be the correct code for above and where can I learn how to store such HTMLs into string or how to use string for such puposes.

Upvotes: 3

Views: 7542

Answers (2)

Rob
Rob

Reputation: 45789

You need to "escape" the quotes in your strings, for example:

string startTag = "<span id=\"productLayoutForm:OurPrice\" class=\"pdp_details_hs18Price\" itemprop=\"price\">";

The \ before the quotes that are inside the string tells the C# compiler that the quotes are part of the string and not the beginning/end of the string.

Upvotes: 4

f2lollpll
f2lollpll

Reputation: 1007

The " sign indicates the start and end of a string.so to use it in the middle of a string you have to escape it, do that by setting a backslash in front of it.. Like this: \"

Upvotes: 1

Related Questions