If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Left/right trim

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-04, 15:55
cytuttle cytuttle is offline
Registered User
 
Join Date: Mar 2004
Posts: 4
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
Reply With Quote
  #2 (permalink)  
Old 04-04-04, 19:50
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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
Reply With Quote
  #3 (permalink)  
Old 04-05-04, 00:39
cytuttle cytuttle is offline
Registered User
 
Join Date: Mar 2004
Posts: 4
Thanks, rokslide! That woked perfect. I am new to ASP and had not used split before.


Quote:
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
Reply With Quote
  #4 (permalink)  
Old 04-05-04, 00:44
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
  #5 (permalink)  
Old 04-12-04, 10:04
thele thele is offline
Registered User
 
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]
Reply With Quote
  #6 (permalink)  
Old 04-12-04, 18:55
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
  #7 (permalink)  
Old 04-12-04, 19:22
thele thele is offline
Registered User
 
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
Reply With Quote
  #8 (permalink)  
Old 04-18-04, 16:03
cytuttle cytuttle is offline
Registered User
 
Join Date: Mar 2004
Posts: 4
Smile

Thanks for all the help!

Quote:
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
Reply With Quote
  #9 (permalink)  
Old 04-18-04, 17:48
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On