Results 1 to 9 of 9

Thread: Left/right trim

  1. #1
    Join Date
    Mar 2004
    Posts
    4

    Unanswered: Left/right trim

    Hello: I am trying to split a picture file name stored in a field into two parts: one being the file name and the other being the file extension. I am able to get the file name using the LEFT trim. How do I get the extension name not knowing how many characters will be in the file name? Any help would be greatly appreciated! Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    why don't you use split??

    Code:
    dim arrFilename, strFileName, strFile, strExtension
    strFileName = "testthis.tst"
    arrFilename = split(strFileName, ".")
    strFile = arrFilename[0]
    strExtension = arrFilename[1]
    HTH

  3. #3
    Join Date
    Mar 2004
    Posts
    4
    Thanks, rokslide! That woked perfect. I am new to ASP and had not used split before.


    Originally posted by rokslide
    why don't you use split??

    Code:
    dim arrFilename, strFileName, strFile, strExtension
    strFileName = "testthis.tst"
    arrFilename = split(strFileName, ".")
    strFile = arrFilename[0]
    strExtension = arrFilename[1]
    HTH

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    No worries. Split never used to be available so you had to use left, instr and mid functions to do what you want.... it's not too hard, but with split it becomes even easier.

  5. #5
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    108
    Just be carefule when using split, in case there is more than one period.

    Example:

    dim arrFilename, strFileName, strExtension, ArraySize
    strFileName = "This.Is.My.File.20040412.txt"
    arrFilename = split(strFileName, ".")
    ArraySize = ubound(arrFilename)
    strExtension = arrFilename[ArraySize]

  6. #6
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Yeah, that would give you a problem with the code as written,...

    Having said that though you could do a simple change that basically determines the last entry in the array (using ubound) and picks that as the extension and then concatenates all other entries in the array and make the filename.

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    108

    Post

    Good call. I forgot that he wanted the filename too.
    So it would be:

    dim arrFilename, strFileName, strExtension, strFileName, ArraySize, z
    strFileName = "This.Is.My.File.20040412.txt"
    arrFilename = split(strFileName, ".")

    ArraySize = ubound(arrFilename)

    strExtension = arrFilename(ArraySize)

    For z = 0 to ArraySize-1
    strFileName = strFileName & arrFilename(z)
    next

  8. #8
    Join Date
    Mar 2004
    Posts
    4

    Smile

    Thanks for all the help!

    Originally posted by thele
    Good call. I forgot that he wanted the filename too.
    So it would be:

    dim arrFilename, strFileName, strExtension, strFileName, ArraySize, z
    strFileName = "This.Is.My.File.20040412.txt"
    arrFilename = split(strFileName, ".")

    ArraySize = ubound(arrFilename)

    strExtension = arrFilename(ArraySize)

    For z = 0 to ArraySize-1
    strFileName = strFileName & arrFilename(z)
    next

  9. #9
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    opps,.. one small mistake....

    dim arrFilename, strFileName, strExtension, strFileName, ArraySize, z
    strFileName = "This.Is.My.File.20040412.txt"
    arrFilename = split(strFileName, ".")

    ArraySize = ubound(arrFilename)

    strExtension = arrFilename(ArraySize)

    For z = 0 to ArraySize-1
    strFileName = strFileName & arrFilename(z) & "."
    next

    strFileName = left(strFileName, len(strFileName)-1)

    because the filename needs the .'s put back in... (I think)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •