Function ParseString(TheString$, DynArray$(), Optional Delim) As Integer
Dim ArrCt As Integer, CurPos As Long, LenAssigned As Long, CurStrLen As Long If IsMissing(Delim) Then Delim = " " ArrCt = 1 CurPos = 1 LenAssigned = 1 CurStrLen = Len(TheString$) Erase DynArray$() Do ReDim Preserve DynArray$(1 To ArrCt) CurStrLen = (InStr(CurPos, TheString$, Delim) - CurPos) If CurStrLen < 0 THEN DYNARRAY$(ARRCT) = RIGHT$(THESTRING$, (LEN(THESTRING$) _ - (LENASSIGNED - 1))) EXIT DO ELSE DYNARRAY$(ARRCT) = MID$(THESTRING$, CURPOS, CURSTRLEN) END IF LENASSIGNED = LENASSIGNED + (LEN(DYNARRAY$(ARRCT)) + LEN(DELIM)) CURPOS = LENASSIGNED ARRCT = ARRCT + 1 LOOP PARSESTRING = UBOUND(DYNARRAY$) END FUNCTION For example you've got a sentence named strSentence which you convert in an array of word. If you use characters other than spaces you have to set the third parameter. |