VBScript str_split function

A VBScript equivalent of PHP’s str_split

Function str_split(string, split_length)

    str_split = false
    If len(string) = 0 Then Exit Function
    If len(split_length) = 0 Then split_length = 1
    If split_length < 1 Then Exit Function

    Dim counter,i,pointer
    counter = len(string)
    counter = counter / split_length + 0.9999
    counter = int(counter) -1

    ReDim tmp_ar(counter)

    For i = 0 to counter
        pointer = i * split_length + 1
        tmp_ar(i) = Mid(string,pointer,split_length)

    str_split = tmp_ar

End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the strings extension