Sign in to follow this  
Followers 0
user52

AutoIt chunk_split(); Similar to php's chunk_split function

1 post in this topic

#include <String.au3>

$str = _
        'this.' & _
        'is.a.' & _
        'strin' & _
        'g'
ConsoleWrite(chunk_split($str, 5) & @CRLF)

ConsoleWrite('============================================================================' & @CRLF)

$str = _
        'this.is.the.start.of' & _
        '.some.string.that.sh' & _
        'ould.be.split.into.c' & _
        'hunks' & _
        ''
ConsoleWrite(chunk_split($str, 20) & @CRLF)

Func chunk_split($body, $chunklen = 76, $end = @CRLF)
    $len = StringLen($body)
    $chunks = Ceiling($len / $chunklen)
    $end_len = StringLen($end)
    $newbody = $body
    $ends = 0
    For $i = $chunklen To $len Step $chunklen
        $pos = ($chunklen * $ends) + ($end_len * $ends) + $chunklen
        $newbody = _StringInsert($newbody, $end, $pos)
        $ends += 1
    Next
    Return $newbody
EndFunc   ;==>chunk_split

#cs
this.
is.a.
strin
g
============================================================================
this.is.the.start.of
.some.string.that.sh
ould.be.split.into.c
hunks
#ce

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0