Results 1 to 2 of 2

Thread: Extract and format non formatted text from string

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Extract and format non formatted text from string

    I have a string which contains html and text.

    If any of the text is not encapsulated by html tags then I want to encapsulate it in <P> tags however certain tags for example anchors and bold tags etc would need to remain within the string.

    i.e the text below

    hgfkjvckvg
    <h1>vhjvhj</h1>
    fhvjvl <a href="">hvlvnlb</a>
    cghcghkgkh
    would become

    <p>hgfkjvckvg</p>
    <h1>vhjvhj</h1>
    <p>fhvjvl<a href="">hvlvnlb</a>
    cghcghkgkh</p>
    I am a little stuck how to provide this behavior. Im wondering if the HTML Aagility pack might help.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Extract and format non formatted text from string

    Hello,

    The HTML Agility Pack is certainly a good place to start, however, it might not be able to do everything that you want.

    You may have to fallback to parsing the string, perhaps with Regular Expressions.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width