Results 1 to 7 of 7

Thread: Easy General VB question...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Easy General VB question...

    Ok, I have a filename saved as a string. The filname is:

    "Superdrag - Lighting the Way"

    I want to separate the two and save them as two separate strings. Like:

    strArtist= Superdrag
    strSong= Lighting the Way

    So basically, I want to find the "-" in the filename and the then take what's on the left side of it and save as one string, and then take what's on the right side of it and save as another string.

    Any help appreciated.

  2. #2

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    how?

    I've never used that before. Can someone give an example?

  4. #4
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    Split returns a one-dimensional array of substrings (zero-based) So...
    VB Code:
    1. arrayStrings = Split("Superdrag - Lighting the Way", " - ")
    and now...

    arrayStrings(0) = "Superdrag"
    arrayStrings(1) = "Lighting the Way"

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    VB Code:
    1. Private Type TFileInfo
    2.   Artist as string
    3.   Song as string
    4. End Type
    5.  
    6. Public Function GetFileInfo(Filename as string) as TFileInfo
    7.   dim parts() as string
    8.   parts=Split(Filename," - ")
    9. On Error resume next
    10.   GetFileInfo.Artist=parts(0)
    11.   GetFileInfo.Song=parts(1)
    12. End Function
    13.  
    14. 'use it like this
    15. dim fInfo as TFileInfo
    16.  
    17. fInfo=GetFileInfo("Superdrag - Lighting the Way")
    18. Msgbox fInfo.Song,,fInfo.Artist

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    ok, but...

    The filename will not always be the same, so I need whatever is on the left of the "-" to be one string.

  7. #7
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    In both examples (mine and Edneeis's), the text on the left side of the string will be stored in the 0-element of the array, and the text on the right side will be stored in the 1-element.

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