Monday 10 March 2014

How to split string without using split function

Dim str,strRes,strchar
str="i am busy with work"
dim strarray()
Redim preserve strarray(0)

for i = 1 to len(str)

    strchar=mid(str,i,1)
    if strchar<>" " then
        strRes=strRes & strchar
    End if
       
        If strchar=" " Then
                  strsize=ubound(strarray)
                  Redim preserve strarray(strsize+1)
                 strarray(strsize+1)=strRes
                 strRes=""
        End If

        If len(str)=i Then
                strsize=ubound(strarray)
                  Redim preserve strarray(strsize+1)
                 strarray(strsize+1)=strRes
        End If
 
Next

for i=1 to ubound(strarray)
msgbox strarray(i)

next

No comments:

Post a Comment