trim string

Discussion in 'ASP General' started by Christopher Brandsdal, Jul 31, 2003.

  1. How do i cut the last 4 characters in a string?
    I know how to cut the 4 first, but i need to cut the last!
    I have a image name like testimage.gif and I want to cut away .gif



    Thanks
    Christopher
    Christopher Brandsdal, Jul 31, 2003
    #1
    1. Advertising

  2. Christopher Brandsdal

    Ray at Guest

    If you just want to cut away the last four, use:

    TheString = Left(TheString, Len(TheString) - 4)

    If you want to get rid of the file extension, here is one of many ways:

    TheString = Left(TheString, InStrRev(TheString, ".") - 1)

    Ray at work

    "Christopher Brandsdal" <> wrote in message
    news:%23Bh%...
    > How do i cut the last 4 characters in a string?
    > I know how to cut the 4 first, but i need to cut the last!
    > I have a image name like testimage.gif and I want to cut away .gif
    >
    >
    >
    > Thanks
    > Christopher
    >
    >
    Ray at, Jul 31, 2003
    #2
    1. Advertising

  3. Christopher Brandsdal

    Evertjan. Guest

    Christopher Brandsdal wrote on 31 jul 2003 in
    microsoft.public.inetserver.asp.general:
    > How do i cut the last 4 characters in a string?
    > I know how to cut the 4 first, but i need to cut the last!
    > I have a image name like testimage.gif and I want to cut away .gif


    vbscript:

    s = left(s,len(s)-4)

    jscript:

    s = s.substring(0,s.length-4)

    not tested

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Jul 31, 2003
    #3
  4. Thank's to both of you!


    "Evertjan." <> skrev i melding
    news:Xns93C99A8931991eejj99@194.109.133.29...
    > Christopher Brandsdal wrote on 31 jul 2003 in
    > microsoft.public.inetserver.asp.general:
    > > How do i cut the last 4 characters in a string?
    > > I know how to cut the 4 first, but i need to cut the last!
    > > I have a image name like testimage.gif and I want to cut away .gif

    >
    > vbscript:
    >
    > s = left(s,len(s)-4)
    >
    > jscript:
    >
    > s = s.substring(0,s.length-4)
    >
    > not tested
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
    Christopher Brandsdal, Jul 31, 2003
    #4
  5. Christopher Brandsdal

    dlbjr Guest

    Why not Right(strData,4)?

    -------------------------------------------------
    d l b j r

    Unambit from meager knowledge of inane others,
    engender uncharted sagacity.
    -------------------------------------------------
    dlbjr, Jul 31, 2003
    #5
  6. Christopher Brandsdal

    Ray at Guest

    He wanted to remove the file extension, not remove the filename.

    Ray at work

    "dlbjr" <> wrote in message
    news:...
    > Why not Right(strData,4)?
    >
    > -------------------------------------------------
    > d l b j r
    >
    > Unambit from meager knowledge of inane others,
    > engender uncharted sagacity.
    > -------------------------------------------------
    >
    >
    Ray at, Jul 31, 2003
    #6
  7. "dlbjr" <> wrote in message
    news:...
    > Why not Right(strData,4)?
    >
    > -------------------------------------------------
    > d l b j r
    >
    > Unambit from meager knowledge of inane others,
    > engender uncharted sagacity.
    > -------------------------------------------------
    >
    >

    OP wants everything BUT the last four (4) characters.
    Chris Hohmann, Jul 31, 2003
    #7
  8. "Christopher Brandsdal" wrote:
    >
    > How do i cut the last 4 characters in a string?
    > I know how to cut the 4 first, but i need to cut
    > the last! I have a image name like testimage.gif
    > and I want to cut away .gif


    Easy way:
    filename.replace(/\.[^.]*?$/,"")

    Silly way:
    filename.split("").reverse().slice(4).reverse().join("")

    Both JScript. The regular expression will properly handle extensions of
    variable length (jpg or jpeg), and will not totally hose such filenames as
    "My.oddly.named.filename.gif".



    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms. Please do not contact
    me directly or ask me to contact you directly for assistance. If your
    question is worth asking, it's worth posting.
    Dave Anderson, Jul 31, 2003
    #8
  9. Christopher Brandsdal

    dlbjr Guest

    okey doke

    -------------------------------------------------
    d l b j r

    Unambit from meager knowledge of inane others,
    engender uncharted sagacity.
    -------------------------------------------------
    dlbjr, Jul 31, 2003
    #9
    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. FAQ server
    Replies:
    0
    Views:
    131
    FAQ server
    Aug 29, 2006
  2. FAQ server
    Replies:
    0
    Views:
    128
    FAQ server
    Oct 26, 2006
  3. FAQ server
    Replies:
    6
    Views:
    205
    Jonas Raoni
    Dec 25, 2006
  4. FAQ server
    Replies:
    26
    Views:
    280
    Dr J R Stockton
    Feb 26, 2007
  5. FAQ server
    Replies:
    2
    Views:
    124
    -Lost
    Apr 24, 2007
Loading...

Share This Page