| |
|
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.
|
 |

04-04-04, 15:55
|
|
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
|
|

04-04-04, 19:50
|
|
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
|
|

04-05-04, 00:39
|
|
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
|
|
|

04-05-04, 00:44
|
|
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. 
|
|

04-12-04, 10:04
|
|
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]
|
|

04-12-04, 18:55
|
|
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.
|
|

04-12-04, 19:22
|
|
Registered User
|
|
Join Date: Jun 2003
Location: Ohio
Posts: 108
|
|
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
|
|

04-18-04, 16:03
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 4
|
|
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
|
|
|

04-18-04, 17:48
|
|
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)
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|