String separation

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

    String separation

    Hi all,
    I am new in VB. My problem is: I have a String type variable with value. I want to get all the words from this string. Such as:

    Dim s As String
    Dim str() As String

    s = "There Is a-tiger"

    I want to see: str(0)=There str(1)=Is str(2)=a str(3)=tiger

    How is is possible? Just please give me idea or tips about that, thanks.
    Last edited by Killer42; Oct 31 '07, 03:09 AM.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Use the Split() function.

    And don't call your array str(). That's the name of a function built into VB, and presumably a reserved word. At least in VB6 it is - not sure about later versions.

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      additionally you could use the mid() function or .substring method.

      Comment

      • shrimant
        New Member
        • Sep 2007
        • 48

        #4
        Originally posted by shaiful
        Hi all,
        I am new in VB. My problem is: I have a String type variable with value. I want to get all the words from this string. Such as:

        Dim s As String
        Dim str() As String

        s = "There Is a-tiger"

        I want to see: str(0)=There str(1)=Is str(2)=a str(3)=tiger

        How is is possible? Just please give me idea or tips about that, thanks.
        As killer said Split is the best bet..Mid would make it too complicated,
        Code:
        str = Split(s,space(1))

        Comment

        Working...