RiCK_420_333 Posted October 7, 2008 Posted October 7, 2008 I have a file which I will import to a variable, but this variable might be very long, and I would like to make it into pieces no longer than 400 char if it is over that. This is what I wrote, however I can't seem to get it quite right, it prints one line short, then the rest at 400, then another short one at the end. I want it to post 400 each time til it has less than 400 charsters to post then it will sho whatever is left on the last one. an excerpt of my code with the issue: $len = StringLen($QueueListFormated) $i = 0 $bufferlength = 400 While $len > 0 $i = $i + 1 If $len > $bufferlength Then $trim = $len - $bufferlength $value = StringTrimRight($QueueListFormated, $trim) _ArrayAdd($QueueList, $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $bufferlength) Else $value = $QueueListFormated _ArrayAdd($QueueList, $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $len) EndIf $len = StringLen($QueueListFormated) WEnd If someone can either help me fix up my code a lil, or offer me a better way to go about this, I would greatly appreciate it. Thanks to all!!
ken82m Posted October 7, 2008 Posted October 7, 2008 (edited) Try This $len = StringLen($QueueListFormated) $i = 0 $bufferlength = 400 While $len > 0 $i = $i + 1 If $len > $bufferlength Then [b] $value = StringLeft($QueueListFormated, 400)[/b] _ArrayAdd($QueueList, $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $bufferlength) Else $value = $QueueListFormated _ArrayAdd($QueueList, $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $len) EndIf $len = StringLen($QueueListFormated) WEnd Edited October 7, 2008 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."
RiCK_420_333 Posted October 7, 2008 Author Posted October 7, 2008 Try This expandcollapse popup $value = StringLeft($QueueListFormated, 400) Thanks for suggesting me something to try, I did try it but it didn't fiix it, still prints out a short, then long, then short, then long, instead of all long til the last one. *shrug*. ken82m Posted October 7, 2008 ken82m Active Members 586 Posted October 7, 2008 hmmm you got me. I tested it this way and it works like it should writing to the text file ;400 a's 400 b's 400 c's 220 d's $QueueListFormated = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb bbbbcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc ccccdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd dddddddddddddddddddddddddddddddd" $len = StringLen($QueueListFormated) $i = 0 $bufferlength = 400 While $len > 0 $i = $i + 1 If $len > $bufferlength Then $value = StringLeft($QueueListFormated, $bufferlength) FileWriteLine("C:\Test.txt", $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $bufferlength) Else $value = $QueueListFormated FileWriteLine("C:\Test.txt", $value) $QueueListFormated = StringTrimLeft($QueueListFormated, $len) EndIf $len = StringLen($QueueListFormated) WEnd "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." smashly Posted October 7, 2008 Posted October 7, 2008 (edited) Hi, #include <Array.au3> ;Only needed for _ArrayDisplay() $String = FileRead(@WindowsDir & "\setuplog.txt"); just a test file that had 765145 characters $sLen = StringLen($String) $Offset = StringRight($String, $sLen - (Floor($sLen/400) * 400)) $aString = StringRegExp($String, "(?s)(.{400})", 3) If Not IsArray($aString) Then Dim $aString[1] $aString[0] = $String Else ReDim $aString[Ubound($aString) + 1] $aString[Ubound($aString) - 1] = $Offset EndIf _ArrayDisplay($aString) Cheers Edited October 7, 2008 by smashly 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 https://www.autoitscript.com/forum/topic/82112-please-help-with-how-to-get-a-long-string-into-400-char-length-peices/ More sharing options... Followers 0
smashly Posted October 7, 2008 Posted October 7, 2008 (edited) Hi, #include <Array.au3> ;Only needed for _ArrayDisplay() $String = FileRead(@WindowsDir & "\setuplog.txt"); just a test file that had 765145 characters $sLen = StringLen($String) $Offset = StringRight($String, $sLen - (Floor($sLen/400) * 400)) $aString = StringRegExp($String, "(?s)(.{400})", 3) If Not IsArray($aString) Then Dim $aString[1] $aString[0] = $String Else ReDim $aString[Ubound($aString) + 1] $aString[Ubound($aString) - 1] = $Offset EndIf _ArrayDisplay($aString) Cheers Edited October 7, 2008 by smashly
Recommended Posts
Recently Browsing 0 members