Jump to content

String buffers (StringFormat ?)


JLC123
 Share

Recommended Posts

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

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

there is always

while stringlen($string) < $num_desired_chars

$string = 'x' & $string

wend

i'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

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

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...