String Manipulation

Discussion in 'ASP General' started by Sergio Orrego, Jul 5, 2006.

  1. I have a text string which comes from a form containing the article text in
    a knowledgebase. Sometimes people enter http links in their text however
    when they show on the webpage they do not show as hyperlinks, because
    obviously they don't gave the link tags around them.

    What I'd like is to manipulate this text string so that wherever there is
    http in it it put's the link tags around it. So what I'm really asking is,
    how can I convert this string:

    And to get to the blah blah site please go to http://blah-blah.com and you
    will find lots of blah blah there.

    Into this:

    And to get to the blah blah site please go to <a
    href="http://blah-blah.com">http://blah-blah.com</a> and you will find lots
    of blah blah there.

    It needs to be versatile as they may enter more than one http link within
    the text.

    Any help appreciated!

    Sergio.
     
    Sergio Orrego, Jul 5, 2006
    #1
    1. Advertising

  2. Sergio Orrego

    Evertjan. Guest

    Sergio Orrego wrote on 05 jul 2006 in
    microsoft.public.inetserver.asp.general:

    > I have a text string which comes from a form containing the article
    > text in a knowledgebase. Sometimes people enter http links in their
    > text however when they show on the webpage they do not show as
    > hyperlinks, because obviously they don't gave the link tags around
    > them.
    >
    > What I'd like is to manipulate this text string so that wherever there
    > is http in it it put's the link tags around it. So what I'm really
    > asking is, how can I convert this string:
    >
    > And to get to the blah blah site please go to http://blah-blah.com and
    > you will find lots of blah blah there.
    >
    > Into this:
    >
    > And to get to the blah blah site please go to <a
    > href="http://blah-blah.com">http://blah-blah.com</a> and you will find
    > lots of blah blah there.
    >
    > It needs to be versatile as they may enter more than one http link
    > within the text.


    That is easy, find seperate words commencing with http:// and convert those
    words to the requested string and replace.

    But how can you access "their text" in serverside ASP?
    Where is "their text" located?

    Please show what you have done sofar in ASP, either vbs or js.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Jul 5, 2006
    #2
    1. Advertising

  3. Sergio Orrego

    Mike Brind Guest

    Sergio Orrego wrote:
    > I have a text string which comes from a form containing the article text in
    > a knowledgebase. Sometimes people enter http links in their text however
    > when they show on the webpage they do not show as hyperlinks, because
    > obviously they don't gave the link tags around them.
    >
    > What I'd like is to manipulate this text string so that wherever there is
    > http in it it put's the link tags around it. So what I'm really asking is,
    > how can I convert this string:
    >
    > And to get to the blah blah site please go to http://blah-blah.com and you
    > will find lots of blah blah there.
    >
    > Into this:
    >
    > And to get to the blah blah site please go to <a
    > href="http://blah-blah.com">http://blah-blah.com</a> and you will find lots
    > of blah blah there.
    >
    > It needs to be versatile as they may enter more than one http link within
    > the text.
    >
    > Any help appreciated!
    >


    Try this pair of functions:

    <%
    function create_links(strText)
    strText = " " & strText
    strText = ereg_replace(strText, "(^|[\n ])([\w]+?://[^ ,""\s<]*)",
    "$1<a href=""$2"" target=""_blank"">$2</a>")
    strText = ereg_replace(strText, "(^|[\n ])((www|ftp)\.[^ ,""\s<]*)",
    "$1<a href=""http://$2"" target=""_blank"">$2</a>")
    strText = ereg_replace(strText, "(^|[\n
    ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)", "$1<a
    href=""mailto:$2@$3"">$2@$3</a>")
    strText = right(strText, len(strText)-1)
    create_links = strText
    end function

    function ereg_replace(strOriginalString, strPattern, strReplacement)
    ' Function replaces pattern with replacement
    dim objRegExp : set objRegExp = new RegExp
    objRegExp.Pattern = strPattern
    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    ereg_replace = objRegExp.replace(strOriginalString, strReplacement)
    set objRegExp = nothing
    end function
    %>

    article_text = create_links(Request.Form("article_text"))

    --
    Mike Brind
     
    Mike Brind, Jul 5, 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. jared in ecs

    Perl string manipulation

    jared in ecs, Oct 22, 2003, in forum: Perl
    Replies:
    2
    Views:
    811
    Roy Johnson
    Oct 22, 2003
  2. Garfield

    String Array Manipulation Problem

    Garfield, Aug 27, 2003, in forum: ASP .Net
    Replies:
    5
    Views:
    2,817
    Michael Lang
    Aug 27, 2003
  3. Aaron

    String Manipulation

    Aaron, Dec 31, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    4,631
    Dave Davidson
    Dec 31, 2003
  4. Aaron

    Advanced String Manipulation (C#)

    Aaron, Jan 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    822
  5. Chris

    String manipulation

    Chris, May 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    452
    Pete Wright
    May 24, 2004
Loading...

Share This Page