Jump to content

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


user52
 Share

Recommended Posts

#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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...