Sign in to follow this  
Followers 0
RiCK_420_333

Please help with: how to get a long string into 400 char length peices?

5 posts in this topic

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


Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

Try This


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


            
        

        
            
                

    
        
            
        
    


            
        

        
            
                
                
                
            
            
                
            
        
        
            




  
  
    
  


        
    

    
        
            Share this post
            
Link to post
            
            
            

            
                Share on other sites
                

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    

            
        
    


    

                    
                
                    
                    
                    






    
    
        
ken82m   

    
        
    
             1
    
        
    

        
            
                Universalist
            
            

            
                

    
        
    

            
            Active Members
            
            
                

    
        
    
             1
    
        
    

                583 posts
                
                

            
        
    
    
        


    

    
        
            
            
                
            
            
        

        
    #4 · 
            Posted 
            
            
            
        
    

    


            
        
            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

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by smashly

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  
Followers 0