Jump to content

StringChunk


erifash
 Share

Recommended Posts

I have created the AutoIt version of PHP's stringchunk function. The function divides the string into equal pieces (with the last piece being anything left over) using a separation character (default is @CRLF). Hope you like it! ;)

Func _StringChunk( $str, $chrs, $sep = @CRLF )
    Local $len = StringLen($str), $ret = ""
    For $i = 1 to $len step $chrs
        $ret &= StringMid($str, $i, $chrs) & $sep
    Next
    Return StringTrimRight($ret, StringLen($sep))
EndFunc

Questions/comments/suggestions are greatly appreciated!

EDIT: Speed improvement.

Edited by erifash
Link to comment
Share on other sites

I'm slightly confused by your description -- does it find the length of the string before the first delimiter and then break up subsequent pieces of the string with the length of the first piece?

Link to comment
Share on other sites

I'm slightly confused by your description -- does it find the length of the string before the first delimiter and then break up subsequent pieces of the string with the length of the first piece?

<{POST_SNAPBACK}>

It doesn't find delimeters, it uses character indexes. Here's an example to help clarify:

$str = "abcdefghijklmnopqrstuvwxyz"
$chunk = 3
MsgBox(0, "regular string", $str)
$chunky = _StringChunk($str, $chunk)
MsgBox(0, "chunky string", $chunky)

I hope that helped.

Link to comment
Share on other sites

Ooh, I understand now and this is quite handy. In fact I know just the thread to report this.

Thanks for the clarification.

<{POST_SNAPBACK}>

Thanks for the compliment. By the way, what thread are you going to report this?
Link to comment
Share on other sites

  • 1 year later...

Sorry to resurrect an old topic but I find this function very useful at times. Also, I have optimized the code for a significant speed improvement so it is worth checking out! ;)

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...