JLC123 Posted October 30, 2007 Share Posted October 30, 2007 Can someone please tell me how to add a buffer to a string so that it is always x characters long? I'm assuming I would use "StringFormat" but I'm not understanding the usage thanks Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
flyingboz Posted October 30, 2007 Share Posted October 30, 2007 Can someone please tell me how to add a buffer to a string so that it is always x characters long? I'm assuming I would use "StringFormat" but I'm not understanding the usagethanksthere is always while stringlen($string) < $num_desired_chars $string = 'x' & $stringwendi'm sure that if you post the actual desired specification, someone will create the stringformat spec for you..$string = StringFormat( "% 5s ",$string) will create a 5 char string Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
JLC123 Posted October 30, 2007 Author Share Posted October 30, 2007 I'm reading a file into an array and then string trimming each line. For $x = 8 to $aRecords[0] - 3 $SRV = StringTrimRight($aRecords[$x], 104) $ACT = StringMid($aRecords[$x], 12, 4) $CHK = StringMid($aRecords[$x], 19, 5) $VID = StringMid($aRecords[$x], 26, 1) $ITM = StringMid($aRecords[$x], 33, 22) $DTE = StringMid($aRecords[$x], 56, 11) $STT = StringMid($aRecords[$x], 67, 8) $SEC = StringMid($aRecords[$x], 79, 3) $BMP = StringMid($aRecords[$x], 104, 8) $VAR = IniRead($INI, $CON, $VID, "NULL") Next $ITM is trimming down to 22 characters, but there aren't always 22 characters there. I need to buffer it so that $ITM is always 22 characters regardless. Make sense? Two wrongs don't make a right, but three lefts do Link to comment Share on other sites More sharing options...
DW1 Posted October 30, 2007 Share Posted October 30, 2007 Just like Flyingboz showed you For $x = 8 To $aRecords[0] - 3 $SRV = StringTrimRight($aRecords[$x], 104) $ACT = StringMid($aRecords[$x], 12, 4) $CHK = StringMid($aRecords[$x], 19, 5) $VID = StringMid($aRecords[$x], 26, 1) $ITM = StringMid($aRecords[$x], 33, 22) While StringLen($ITM) < 22 $ITM = $ITM & "X" ; or if you want the buffer the other way "$ITM = "X" & $ITM" WEnd $DTE = StringMid($aRecords[$x], 56, 11) $STT = StringMid($aRecords[$x], 67, 8) $SEC = StringMid($aRecords[$x], 79, 3) $BMP = StringMid($aRecords[$x], 104, 8) $VAR = IniRead($INI, $CON, $VID, "NULL") Next AutoIt3 Online Help Link to comment Share on other sites More sharing options...
JLC123 Posted October 30, 2007 Author Share Posted October 30, 2007 Thank you. Two wrongs don't make a right, but three lefts do 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