cut something from a string

Discussion in 'ASP General' started by Christopher Brandsdal, Feb 3, 2006.

  1. Hi!

    I guess this is easy, but I ask anyway :)

    How can I cut 'www.' and '.no' or '.com' from a string?

    example input:

    www.norway.no
    www.somewhere.com

    I want this output:

    norway
    somewhere

    How can I do this?

    Best regards,
    Christopher
     
    Christopher Brandsdal, Feb 3, 2006
    #1
    1. Advertising

  2. Christopher Brandsdal

    McKirahan Guest

    "Christopher Brandsdal" <> wrote in message
    news:...
    > Hi!
    >
    > I guess this is easy, but I ask anyway :)
    >
    > How can I cut 'www.' and '.no' or '.com' from a string?
    >
    > example input:
    >
    > www.norway.no
    > www.somewhere.com
    >
    > I want this output:
    >
    > norway
    > somewhere
    >
    > How can I do this?


    <%
    Dim arrURL
    Dim strURL
    strURL = "www.norway.no"
    arrURL = Split(strURL,".")
    Response.Write arrURL(1)
    %>
     
    McKirahan, Feb 4, 2006
    #2
    1. Advertising

  3. Christopher Brandsdal

    Evertjan. Guest

    McKirahan wrote on 04 feb 2006 in microsoft.public.inetserver.asp.general:

    > "Christopher Brandsdal" <> wrote in message
    > news:...
    >> Hi!
    >>
    >> I guess this is easy, but I ask anyway :)
    >>
    >> How can I cut 'www.' and '.no' or '.com' from a string?
    >>
    >> example input:
    >>
    >> www.norway.no
    >> www.somewhere.com
    >>
    >> I want this output:
    >>
    >> norway
    >> somewhere
    >>
    >> How can I do this?

    >
    > <%
    > Dim arrURL
    > Dim strURL
    > strURL = "www.norway.no"
    > arrURL = Split(strURL,".")
    > Response.Write arrURL(1)
    > %>


    <%
    strURL = "www.north.of.norway.no"
    arrURL = Split(strURL,".")
    r = arrURL(1)
    for i=2 to ubound(arrURL)-1
    r = r & "." & arrURL(i)
    next
    Response.Write r
    %>

    or better imho:

    <%
    strURL = "www.north.of.norway.no"
    Set regEx = New RegExp
    regEx.Pattern = "^[^\.]+\.(.*)\.[^\.]+$"
    Response.Write regEx.Replace(strURL, "$1")
    %>





    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 4, 2006
    #3
  4. Christopher Brandsdal

    Roland Hall Guest

    "McKirahan" wrote in message
    news:p...
    : "Christopher Brandsdal" <> wrote in message
    : news:...
    : > Hi!
    : >
    : > I guess this is easy, but I ask anyway :)
    : >
    : > How can I cut 'www.' and '.no' or '.com' from a string?
    : >
    : > example input:
    : >
    : > www.norway.no
    : > www.somewhere.com
    : >
    : > I want this output:
    : >
    : > norway
    : > somewhere
    : >
    : > How can I do this?
    :
    : <%
    : Dim arrURL
    : Dim strURL
    : strURL = "www.norway.no"
    : arrURL = Split(strURL,".")
    : Response.Write arrURL(1)
    : %>

    function justTheBeef(url)
    justTheBeef = split(url,".")(1)
    end function

    Response.Write justTheBeef("www.norway.no")

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Feb 5, 2006
    #4
    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. Ian Collins

    cut a string in file

    Ian Collins, Mar 30, 2008, in forum: C++
    Replies:
    4
    Views:
    1,254
    Default User
    Mar 30, 2008
  2. Christopher Brandsdal

    cut from string using JScript

    Christopher Brandsdal, Jun 3, 2004, in forum: ASP General
    Replies:
    10
    Views:
    236
    Christopher Brandsdal
    Jun 4, 2004
  3. Cut String & Insert in String

    , May 14, 2007, in forum: ASP General
    Replies:
    5
    Views:
    160
    Evertjan.
    May 14, 2007
  4. Toki Toki
    Replies:
    4
    Views:
    137
    Toki Toki
    Aug 17, 2008
  5. Pål Bergström

    Cut a string if length > n

    Pål Bergström, Aug 19, 2008, in forum: Ruby
    Replies:
    14
    Views:
    203
    Pål Bergström
    Aug 20, 2008
Loading...

Share This Page