Convert plain text string to HTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis

    #1

    Convert plain text string to HTML

    Is there anything built in to vb.net that will take a plain text string
    and reformat it as HTML? What I mean is:

    o replace newlines with <BR>
    o replace " with &quot;
    o etc.

    I am using vb.net 2003.

    Thanks,

    --

    Dennis
  • Herfried K. Wagner [MVP]

    #2
    Re: Convert plain text string to HTML

    "Dennis" <nobody@imyisp. invalidschrieb:
    Is there anything built in to vb.net that will take a plain text string
    and reformat it as HTML? What I mean is:
    >
    o replace newlines with <BR>
    o replace " with &quot;
    o etc.
    >
    I am using vb.net 2003.

    The simplest way to do this is using 'Replace'. In addition check out
    'HttpUtility.Ht mlEncode'.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Rad [Visual C# MVP]

      #3
      Re: Convert plain text string to HTML

      On Wed, 03 Jan 2007 11:19:00 -0500, Dennis wrote:
      Is there anything built in to vb.net that will take a plain text string
      and reformat it as HTML? What I mean is:
      >
      o replace newlines with <BR>
      o replace " with &quot;
      o etc.
      >
      I am using vb.net 2003.
      >
      Thanks,
      For the <BRyou'll have to make do with the string.replace( ). For the
      other html entities like &quot; &gt; etc you can use the
      HttpUtility.HTM LEncode() function

      --
      Bits.Bytes

      Comment

      • =?Utf-8?B?RGVubmlz?=

        #4
        Re: Convert plain text string to HTML

        Just curious as to why replace with &quot, etc. I generate an HTML code
        within VB from a database and save it as an HTM file. It displays fine in
        internet explorer. Is there some problem if I were to send this page via
        e-mail or something?
        --
        Dennis in Houston


        "Rad [Visual C# MVP]" wrote:
        On Wed, 03 Jan 2007 11:19:00 -0500, Dennis wrote:
        >
        Is there anything built in to vb.net that will take a plain text string
        and reformat it as HTML? What I mean is:

        o replace newlines with <BR>
        o replace " with "
        o etc.

        I am using vb.net 2003.

        Thanks,
        >
        For the <BRyou'll have to make do with the string.replace( ). For the
        other html entities like " etc you can use the
        HttpUtility.HTM LEncode() function
        >
        --
        Bits.Bytes

        >

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Convert plain text string to HTML

          "Dennis" <Dennis@discuss ions.microsoft. comschrieb:
          Just curious as to why replace with &quot, etc. I generate an HTML code
          within VB from a database and save it as an HTM file. It displays fine in
          internet explorer. Is there some problem if I were to send this page via
          e-mail or something?
          There is generally no reason to use '&quot;' instead of the double quotation
          mark character except if the encoding used to save the file does not contain
          the character (which is very unlikely nowadays) or in attribute values
          surrounded by double quotation marks.

          Valid XHTML:

          * '<img src="1.gif" alt="Bla &quot;Bla&qu ot; Bla"/>'
          * '<img src="1.gif" alt='Bla "Bla" Bla'/>'

          Invalid XHTML:

          * '<img src="1.gif" alt="Bla "Bla" Bla"/>'

          The same applies to '&apos;' vs. the single quotation mark character.

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: Convert plain text string to HTML

            Herfried,

            In my idea is the double space still a problem
            &nbsp

            Cor

            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
            news:%23XxcQ$5L HHA.3588@TK2MSF TNGP06.phx.gbl. ..
            "Dennis" <Dennis@discuss ions.microsoft. comschrieb:
            >Just curious as to why replace with &quot, etc. I generate an HTML code
            >within VB from a database and save it as an HTM file. It displays fine
            >in
            >internet explorer. Is there some problem if I were to send this page via
            >e-mail or something?
            >
            There is generally no reason to use '&quot;' instead of the double
            quotation mark character except if the encoding used to save the file does
            not contain the character (which is very unlikely nowadays) or in
            attribute values surrounded by double quotation marks.
            >
            Valid XHTML:
            >
            * '<img src="1.gif" alt="Bla &quot;Bla&qu ot; Bla"/>'
            * '<img src="1.gif" alt='Bla "Bla" Bla'/>'
            >
            Invalid XHTML:
            >
            * '<img src="1.gif" alt="Bla "Bla" Bla"/>'
            >
            The same applies to '&apos;' vs. the single quotation mark character.
            >
            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Convert plain text string to HTML

              "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
              In my idea is the double space still a problem
              &nbsp
              Which double space?

              '&nbsp;' is not the same as " ". The first one is a non-breaking space
              (thus '&nbsp;') which prevents insertion of soft line breaks.

              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

              Comment

              Working...