I have multiple pre tags like below.. an example...
test
Code
Hello
1Code
Hello
2Code
Hello
3I need to get text value from pre tags and strip out the html tags.
O/P
Hello 1
Hello 2
Hello 3
test
Hello
1Hello
2Hello
3Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Apr 11, 2011, 11:01 AM EDT
Prabhakar PariharRank #1,307 · 1.3K reputationPosted Apr 11, 2011, 4:25 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Apr 11, 2011, 7:55 AM EDT
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Apr 11, 2011, 8:24 AM EDT
String result = Regex.Replace(strLine, @"<[^>]*>", String.Empty); //strLine is each line of text
Suthish NairRank #92 · 22.8K reputationPosted Apr 11, 2011, 9:26 AM EDT
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Apr 11, 2011, 12:47 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Apr 11, 2011, 10:28 PM EDT
Suthish, do you need the output to be like you show or like the output produced by the code that Vulpes posted? The output using the RegEx does not have an embedded space, which is consistent with the way the text would look in a browser, correct?
The attached zip has code that produces the same output, including the absence of a space. If you need greater control of the data then you need to be more specific about what you need. I assume that since you accepted Vulpes's reply, you don't need the additional text.
Note that the project for the source code needs a reference to "Microsoft HTML Object Library".