striping text of special characters before displaying on webpage

Discussion in 'ASP .Net' started by ebade2000@gmail.com, Sep 12, 2006.

  1. Guest

    I have this project I am working and I have two tasks

    I have a text form that takes in a users input and it is supposed to be
    stored in a database and can be viewed from a webpage. I want to be
    able to display the text with html special characters like "<", ">" (if
    the user typed them in) without it being confused for html code and...

    I want to be able to replace a newline character with a "/r/n" whenever
    it is used in the text.
    , Sep 12, 2006
    #1
    1. Advertising

  2. Hi ebade2000,

    String.Replace and Server.HtmlEncode should do the trick.

    string s = "<display \r\n me>";
    s = Server.HtmlEncode(s); // converts < > etc
    s = s.Replace("\r\n", "<br>"); // replaces string breaks with html
    breaks
    Response.Write(s);



    On Tue, 12 Sep 2006 02:08:12 +0200, <> wrote:

    > I have this project I am working and I have two tasks
    >
    > I have a text form that takes in a users input and it is supposed to be
    > stored in a database and can be viewed from a webpage. I want to be
    > able to display the text with html special characters like "<", ">" (if
    > the user typed them in) without it being confused for html code and...
    >
    > I want to be able to replace a newline character with a "/r/n" whenever
    > it is used in the text.
    >




    --
    Happy Coding!
    Morten Wennevik [C# MVP]
    Morten Wennevik, Sep 12, 2006
    #2
    1. Advertising

  3. Guest

    Thanks that helps a whole lot.

    Bade

    Morten Wennevik wrote:
    > Hi ebade2000,
    >
    > String.Replace and Server.HtmlEncode should do the trick.
    >
    > string s = "<display \r\n me>";
    > s = Server.HtmlEncode(s); // converts < > etc
    > s = s.Replace("\r\n", "<br>"); // replaces string breaks with html
    > breaks
    > Response.Write(s);
    >
    >
    >
    > On Tue, 12 Sep 2006 02:08:12 +0200, <> wrote:
    >
    > > I have this project I am working and I have two tasks
    > >
    > > I have a text form that takes in a users input and it is supposed to be
    > > stored in a database and can be viewed from a webpage. I want to be
    > > able to display the text with html special characters like "<", ">" (if
    > > the user typed them in) without it being confused for html code and...
    > >
    > > I want to be able to replace a newline character with a "/r/n" whenever
    > > it is used in the text.
    > >

    >
    >
    >
    > --
    > Happy Coding!
    > Morten Wennevik [C# MVP]
    , Sep 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nanda Kumar

    Displaying special characters in datagrid

    Nanda Kumar, May 9, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    153
    Eliyahu Goldin
    May 9, 2005
  2. Kevin Blount
    Replies:
    2
    Views:
    118
    Kevin Blount
    Dec 6, 2005
  3. johngnub
    Replies:
    1
    Views:
    91
    J. Gleixner
    Apr 10, 2007
  4. johkar

    Table row striping

    johkar, Jun 20, 2006, in forum: Javascript
    Replies:
    8
    Views:
    91
    Dr John Stockton
    Jun 22, 2006
  5. Replies:
    3
    Views:
    95
    Randy Webb
    Jul 17, 2006
Loading...

Share This Page