String Manipulation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akoymakoy
    New Member
    • Oct 2006
    • 42

    #1

    String Manipulation

    Hi

    I would like to extract every words in text1.text and assign each word in an array

    for example:
    the quick brown fox jumps over the lazy dog

    wordset(0) = the
    wordset(1) = quick
    wordset(2) = brown
    wordset(3) = fox

    until the end of the sentence


    Thanks for the help
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by akoymakoy
    Hi

    I would like to extract every words in text1.text and assign each word in an array

    for example:
    the quick brown fox jumps over the lazy dog

    wordset(0) = the
    wordset(1) = quick
    wordset(2) = brown
    wordset(3) = fox

    until the end of the sentence


    Thanks for the help
    Use this for splitting strings into an array using the default space character:
    Code:
    myArray = Split(myString)
    If you want to use a different delimiter such as a comma use this:
    Code:
    myArray = Split(myString, ",")

    Comment

    • akoymakoy
      New Member
      • Oct 2006
      • 42

      #3
      ive done this and it worked
      Thanks

      my problem now is how do i put it on a 2 dimensional array such that the first sentence goes to the first column and the succeeding sentences goes to the next:

      ex:

      myArray(0,1) = I
      myArray(0,2) = am
      myArray(0,3) = fat

      myArray(1,1) = I
      myArray(1,2) = am
      myArray(1,3) = thin

      i tried using myArray(0,1)=sp lit(myString," ") but it returned an array error

      myArray is like this

      dim myArray as variant

      Thanks once again

      Comment

      • scripto
        New Member
        • Oct 2006
        • 143

        #4
        here you go

        Dim str As String
        Dim arry1() As String
        Dim arry2() As String
        Dim arry3() As String

        str = "i am fat. i am thin"

        arry1 = Split(str, ".")
        arry2 = Split(arry1(0))
        arry3 = Split(LTrim(arr y1(1)))

        Debug.Print arry1(0) & arry1(1)
        Debug.Print arry2(0) & " " & arry2(1) & " " & arry2(2)
        Debug.Print arry3(0) & " " & arry3(1) & " " & arry3(2)

        Comment

        Working...