erifash Posted September 9, 2005 Share Posted September 9, 2005 (edited) 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 January 27, 2007 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
LxP Posted September 9, 2005 Share Posted September 9, 2005 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 More sharing options...
erifash Posted September 9, 2005 Author Share Posted September 9, 2005 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. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
LxP Posted September 10, 2005 Share Posted September 10, 2005 Ooh, I understand now and this is quite handy. In fact I know just the thread to report this. Thanks for the clarification. Link to comment Share on other sites More sharing options...
erifash Posted September 10, 2005 Author Share Posted September 10, 2005 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? My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
LxP Posted September 10, 2005 Share Posted September 10, 2005 String Insert -- I'm Brain Fried I'm trying to insert a hyphen in my string every 3rd letter or number... but every attempt I've tried for the past couple of hours has failed.<{POST_SNAPBACK}> Link to comment Share on other sites More sharing options...
erifash Posted December 3, 2006 Author Share Posted December 3, 2006 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! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now