Visual Basic 6 function "chunk_split"

Go back

Below you'll find the source for the Visual Basic 6 function chunk_split.

Attribute VB_Name = "modChunkSplit"
' This function is downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

' Split a string into smaller chunks
' Same syntax as the PHP function 'chunk_split'
' See also:
' @param    string  body        The string to be chunked.
' @param    integer chunklen    The chunk length. Defaults to 76
' @param    string  endstr      The line ending sequence. Defaults to vbCrLf
' @return   string              Returns the chunked string
' @author   Stefan Thoolen <>
Public Function chunk_split(ByVal body As String, Optional ByVal chunklen As Integer = 76, Optional endstr As String = vbCrLf)
    Dim l As Long, retval As String
    For l = 1 To Len(body) Step chunklen
        retval = retval & Mid(body, l, chunklen) & endstr
    Next l
    chunk_split = retval
End Function