09-07-2003, 08:23 AM
If i have a filename like "test - info on test.txt", what is the best way to just obtain the characters before the "-" symbol?
09-07-2003, 08:38 AM
May be this helps...
Try InStr() function
Dim sFile As String
sFile = "test - info on test.txt"
sCheck = InStr(1, sFile, "-", vbTextCompare)
sFile = Trim$(Mid$(sFile, 1, sCheck -1))
Chris J Locke
09-07-2003, 08:39 AM
the command INSTR will give you a position of a string within a string. So, if you wanted to search "banana" for "nana", you'd use:
?instr(1,"banana","nana") which would return 3 - nana begins at the 3rd character. If it returned 0, the string wasn't found. The first 1 denotes that you want to start searching at character 1 - ie, the beginning.
So, you'd search for a dash. Store it in a variable...li_pos=instr(1,ls_filename,"-")You then want to extract that many characters from the left of the string.ls_newFilename=left$(ls_filename,li_pos)However, this would also contain the dash. And the space (if it had one). So go back a character and tidy it up...ls_newFilename=trim$(left$(ls_filename,li_pos-1))Trim removes any spaces.
I think thats about it... ;)
Edit:Oops, beaten to it! :o