Split String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaiful
    New Member
    • Oct 2007
    • 89

    Split String

    Hi all I have a simple problem with string. I want to split string, such as:
    dim s as string
    dim k(3) as string
    s="aa1,bv1,cc1, dt1"

    i want to split the value in k,
    k(0)=aa1
    k(1)=bv1
    k(2)=cc1
    k(3)=dt1

    Pls give me any easy idea to solve it, thx advance
  • Torgg
    New Member
    • Dec 2007
    • 41

    #2
    You almost had it, give this a try... I tested it and it worked.

    Code:
    Dim s As String
    Dim k() As String
    s = "aa1,bv1,cc1,dt1"
    k = Split(s, ",")
    
    MsgBox k(0)
    MsgBox k(1)
    MsgBox k(2)
    MsgBox k(3)
    Hope this helps,
    Torgg

    Comment

    • shaiful
      New Member
      • Oct 2007
      • 89

      #3
      Originally posted by Torgg
      You almost had it, give this a try... I tested it and it worked.

      Code:
      Dim s As String
      Dim k() As String
      s = "aa1,bv1,cc1,dt1"
      k = Split(s, ",")
      
      MsgBox k(0)
      MsgBox k(1)
      MsgBox k(2)
      MsgBox k(3)
      Hope this helps,
      Torgg

      Thx a lot Torgg, its working

      Comment

      • shaiful
        New Member
        • Oct 2007
        • 89

        #4
        Originally posted by shaiful
        Thx a lot Torgg, its working
        I have one one more question about this split string. if string is:
        s="a12.b2.c2.d. e.f2........"
        and how i will get all those data from s, because i dont know how many total data in there. if i use like as u said k(0), k(1)..... but if s is finished and its say Error, so do i=u have any idea abt this pls, thx again

        Comment

        • CyberSoftHari
          Recognized Expert Contributor
          • Sep 2007
          • 488

          #5
          You will use
          [CODE=vb]Dim k(10) as String[/CODE] did you tried ReDim …..?
          Note: Try your self a bit more and post your query. Doing homework is prohibited here and you have to read posting guidelines.
          Last edited by CyberSoftHari; Jan 3 '08, 03:34 AM. Reason: code Tag

          Comment

          • vikas000000a
            New Member
            • Jan 2008
            • 46

            #6
            Originally posted by shaiful
            I have one one more question about this split string. if string is:
            s="a12.b2.c2.d. e.f2........"
            and how i will get all those data from s, because i dont know how many total data in there. if i use like as u said k(0), k(1)..... but if s is finished and its say Error, so do i=u have any idea abt this pls, thx again
            It can be checked using UBound as under:

            Code:
            Dim s As String
            Dim k() As String
            s = "aa1,bv1,cc1,dt1"
            k = Split(s, ",")
            
            for i=0 to UBound(k)
                MsgBox k(i)
            next i
            Hope your problem is solved with this.

            Comment

            Working...