Jump to content
Sign in to follow this  
erifash

StringChunk

Recommended Posts

erifash

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

Share this post


Link to post
Share on other sites
LxP

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?

Share this post


Link to post
Share on other sites
erifash

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.

Share this post


Link to post
Share on other sites
LxP

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

Thanks for the clarification.

Share this post


Link to post
Share on other sites
erifash

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?

Share this post


Link to post
Share on other sites
erifash

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! ;)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.