Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:58:18+00:00 2026-06-15T22:58:18+00:00

I have one String variable that contains HTML data.Now i want to split that

  • 0

I have one String variable that contains HTML data.Now i want to split that html string into multiple string and then finally merge those strings into single one.

This is html string:

<p><span style="text-decoration: underline; color: #ff0000;"><strong>para1</strong></span></p>
<p style="text-align: center;"><strong><span style="color: #008000;">para2</span> स्द्स्द्सद्स्द para2 again<br /></strong></p>
<p style="text-align: left;"><strong><span style="color: #0000ff;">para3</span><br /></strong></p>

And this is my expected output:

<p><span style="text-decoration: underline; color: #ff0000;"><strong>para1</strong></span><strong><span style="color: #008000;">para2</span>para2 again<br /></strong><strong><span style="color: #0000ff;">para3</span><br /></strong></p>

My Split Logic is given below…

  1. Split the HTML string into token based on </p> tag.
  2. And take the first token and store it in separate string variable(firstPara).
  3. Now take the each and every token and then remove any tag starting with<p and also ending with </p>.And store each value in separate variable.

4.Then take first token named firstPara and replace the tag </p> and then append each every token that we got through the step 3.

5.So,Now the variable firstPara has whole value…

  1. Finally, we just append </p> at the end of the firstPara…

This is my problem…

Could you please step me to get out of this issue…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:58:20+00:00Added an answer on June 15, 2026 at 10:58 pm

    Here is regex example how to do it.

    String pattern = @"(?<=<p.*>).*(?=</p>)";
    var matches = Regex.Matches(text, pattern);
    StringBuilder result = new StringBuilder();
    result.Append("<p>");
    foreach (Match match in matches)
    {
        result.Append(match.Value);
    }
    result.Append("</p>");
    

    And this is how you should do it with Html Agility Pack

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml(text);
    var nodes = doc.DocumentNode.SelectNodes("//p");
    StringBuilder result = new StringBuilder();
    result.Append("<p>");
    foreach (HtmlNode node in nodes)
    {
        result.Append(node.InnerHtml);
    }
    result.Append("</p>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have a table that contains in one column a variable length delimited string
I have a string variable that contains a lot of HTML markup and I
I have a variable s which contains a one letter string s = 'a'
I have a string variable Result that contains a string like: <field1>text</field1><field2>text</field2> etc.. I
I have PHP variable that contains string like: http://domain.com/uploads/image1.jpg|||http://domain.com/uploads/image2.jpg|||http://domain.com/uploads/image3.jpg|||... I need to get first
I have a HTML inside a string variable, which contains some <img> tags. I
I have a variable that contains a long string. (specifically it contains a few
I have a smarty template that contains a variable in which data is loaded
I have one string like 8/29/2011 11:16:12 AM . I want to save in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.