Results 1 to 7 of 7

Thread: Crazy string manipulation

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    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
    Mike

  2. #2
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    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

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    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
    Mike

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Re: Crazy string manipulation

    Awesome!!
    Mike

  5. #5
    Lively Member Garrcomm's Avatar
    Join Date
    Jul 2009
    Location
    the Netherlands
    Posts
    87

    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.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 1999
    Location
    Nashville, TN
    Posts
    114

    Resolved <Resolved> Crazy string manipulation

    Thanks.

    Strings have always driven me nuts and you made it look easy.

    Very much appreciated.
    Mike

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    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
  •  



Click Here to Expand Forum to Full Width