LSet$ ( string$,size )

Parameters

string - the string to pad or cut

size - the exact length the result should be

Description

Returns the string forced to an exact length, padded on the right with spaces.

LSet( "ab",5 ) gives "ab ". If the string is already longer than the requested size it is cut down instead, keeping the leftmost characters: LSet( "abcdef",3 ) gives "abc". Either way the result is exactly the length you asked for.

That fixed width is the point. With a monospaced font, LSet lets you lay out columns without measuring anything - a scoreboard where names line up on the left and scores on the right, a debug overlay of variable names and values, or a fixed-record save format where every entry occupies the same number of bytes.

Pair it with RSet, which pads on the left instead, to get names left-aligned and numbers right-aligned in the same table.

The size must be 0 or more; a negative value raises a runtime error.

See also: RSet, Left, String, Len.

Example

; LSet Example
; ------------

; LSet$ left-justifies a string in a field of the given width,
; padding it with spaces (or chopping it) to exactly that size.

Print "High-score table (names padded to 16 characters with LSet$):"
Print ""
Print LSet$("Name",16)+"Score"
Print LSet$("Robo",16)+"1250"
Print LSet$("Zelda",16)+"980"
Print LSet$("Maximillian",16)+"720"

; The quotes show exactly where the padding goes
Print ""
Print "LSet$('Robo',16) = '"+LSet$("Robo",16)+"'"

; A string longer than the field is cut down to fit
Print "LSet$('Maximillian the Unstoppable',16) = '"+LSet$("Maximillian the Unstoppable",16)+"'"

Print ""
Print "Press any key to close the example"
WaitKey

End

Index