CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Guest

    help with strings

    i have a function that takes one large string. the string has tree words.
    "computer screen button". there is space between them. i need a code for parssing this string. i want to put each word in array.
    thanks



  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: help with strings

    If i'm correct, you want to place every word seperated with a space, into a string? Ok, try this:

    dim myArray() as string
    public chopThemUp(strToChop as string)

    dim myCount as integer
    myCount = 1
    redim myArray(myCount)

    for t=1 to len(strToChop)

    ' get one character
    myChar = mid(strToChop,t,1)
    if mychar = " " then
    ' if a space, create new array element
    myCount = myCount + 1
    redim preserve myArray(myCount)
    else
    ' when not a space, add char to last array element
    myArray(myCount-1) = myArray(myCount-1) & myChar
    end if

    next t

    end sub



    This code will place all words into seperate array elements by doing a check on each character, if it's a space, it will create a new array element, if not, it will append the char to the last element of the char.

    Tom Cannaerts
    [email protected]

    The best way to escape a problem, is to solve it.
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    May 1999
    Posts
    3,332

    Re: help with strings

    in VB 6 there is a split function that allows you to do that in one line.

    dim a() as string
    a = split("yourstringgoes here", " " )





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

Featured