split function - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

split function

hi
i need to make a program using vb4. vb4 doesnt seem to have the split function. is there a way to find the source for the split function?

Comments

  • GenjuroGenjuro Posts: 913Member
    : hi
    : i need to make a program using vb4. vb4 doesnt seem to have the split function. is there a way to find the source for the split function?
    :

    Write it on your own: it's not that hard. I can offer you an algorithm to do so; but as far as coding it goes, well, it makes for a nice excercice.

    You should:
    1) count how many separators (ie: "|" characters) there are in the string.
    2) ReDim an array so that it has enough elements.

    Then, while there are separators in the string (start a loop), you should :
    3) keep the "current piece start" index - either the beginning of the string you need splitted, or the position of the last separator you found - and search from after there for another separator (if there's no separator, then you're checking the last token): the "current piece end"
    4) Cut with Mid, starting from the "current piece start" character, a number of characters equal to ("current piece end" - "current piece start"), and put the token in your array.
    5) Replace the "current piece start" with the "current piece end", and start over.
    When there are no more tokens (Instr for a separator returns 0), then cut the last piece (the "current piece end" is equal to Len(string) ).

    6) exit the loop and return to the caller the array you generated.
Sign In or Register to comment.