Results 1 to 3 of 3

Thread: Separating A String Into Strings?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2000
    Location
    Belfast
    Posts
    109

    Separating A String Into Strings?

    Hi I have a string which is "Track 04 (3.51)". I'd like to be able to rip the information in the string so I have:

    strTrackName = "Track 04"
    strDuration = "3.51"

    Anyone know a good way of doing this? Thanks in advance.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    VB Code:
    1. Dim strInfo As String = "Track 04 (3.51)"
    2.         Dim strTrackName As String = strInfo.Substring(0, strInfo.IndexOf("(") - 1)
    3.         Dim c As Char() = "()".ToCharArray
    4.         Dim strDuration As String = strInfo.Split(c)(1)
    5.         MessageBox.Show("Track: " & strTrackName & Environment.NewLine & "Time: " & strDuration)
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Hyperactive Member sw_is_great's Avatar
    Join Date
    Nov 2003
    Posts
    330
    Hi
    This may work.I did not run it , just writing directly(just check for silly mikstakes if any).
    Made it simple for u :


    Dim origStr as String = "Track 04 (3.51)"
    Dim newStr1 as String
    Dim newStr2 as String
    Dim pos1,pos2 as Integer

    pos1 = origStr.IndexOf("(")
    pos2 = origStr.IndexOf(")")

    newStr1 = origStr.Substring(0,pos1-1)
    newStr2 = origStr.Substring(pos1,(pos2-pos1-1))
    Regards

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