|
-
Jul 10th, 2009, 09:09 AM
#1
Thread Starter
Lively Member
Crazy string manipulation
Been a long time since I've had to write any code and string always seemed to mess me up anyways. So I need a little help.
First part:
Below is an example of a folder name I need to parse and move to another file. I can move the files fine but I need to designate which folder to place the folder in.
The folders names from reverse always will have the "_" in the same location in the string so I need to strip off that part of the string and keep the first part for the folder rename. (ie "This string seems to never ever end")
Second Part:
The "imhere" part I need to read and sort because it could also say "ithere" or "imaway". So I need to isolate what the word is then I can run it through a Case or if/then so I can designate further whigh folder to drop the whole folder I'm reading in.
This string seems to never ever end_imhere_Date_060809_Time_161136
Any help would be greatly appreciated.
Mike
-
Jul 10th, 2009, 09:18 AM
#2
Lively Member
Re: Crazy string manipulation
From the right, there are always 5 parts devided by underscores?
If so, you could use InStrRev or Split.
It could be:
Code:
Dim s() As String, filename As String
filename = "This string seems to never ever end_imhere_Date_060809_Time_161136"
s = Split(filename, "_")
Dim strtime As String, strdate As String, strtag As String, strfn As String
strtime = s(UBound(s))
strdate = s(UBound(s) - 2)
strtag = s(UBound(s) - 4)
strfn = Left(filename, Len(filename) - Len(strtag) - Len(strdate) - Len(strtime) - 13)
MsgBox "Time: " & strtime & vbCrLf & "Date: " & strdate & vbCrLf & "Tag: " & strtag & vbCrLf & "Name: " & strfn
Last edited by Garrcomm; Jul 10th, 2009 at 09:24 AM.
Reason: Added [code] tag
-
Jul 10th, 2009, 09:33 AM
#3
Thread Starter
Lively Member
Re: Crazy string manipulation
Yes, 5 parts separated by underscores from the right. Then isolate the word between the 4th and 5th underscore.
Trying your code now.
Mike
-
Jul 10th, 2009, 09:38 AM
#4
Thread Starter
Lively Member
Re: Crazy string manipulation
-
Jul 10th, 2009, 09:41 AM
#5
Lively Member
Re: Crazy string manipulation
It worked for you? Good 
The solution is quite easy; I seperated the string by underscores into an array. I took the last values (ubound gives the highest index of an array).
Only the name was a little more difficult, since in my example the name may also contain underscores. I took the whole name minus the length of all extracted parts.
-
Jul 10th, 2009, 10:12 AM
#6
Thread Starter
Lively Member
<Resolved> Crazy string manipulation
Thanks.
Strings have always driven me nuts and you made it look easy.
Very much appreciated.
-
Jul 10th, 2009, 11:06 AM
#7
Re: Crazy string manipulation
As there could be subfolders placed in the working directory unrelated to your process in the future you should always check first that the pattern is being met, e.g. there are 6 array elements and relative array elements can be converted to date and time. If pattern is incorrect then it is an unrelated folder and should be skipped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|