mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-22 04:25:08 +00:00
62 lines
1.7 KiB
Text
62 lines
1.7 KiB
Text
[[LSET]] left-justifies a fixed length string expression based on the size of the [[STRING]] variable and string expression.
|
|
|
|
|
|
{{PageSyntax}}
|
|
: [[LSET]] {stringVariable = stringExpression | stringExpression1 = stringExpression2}
|
|
|
|
|
|
{{PageDescription}}
|
|
* If the string expression is longer than a fixed length string variable the value is truncated from the right side in LSET or [[RSET]].
|
|
* If the LSET string expression is smaller, spaces will occupy the extra positions to the right in the string.
|
|
* LSET can be used with a [[FIELD]] or [[TYPE]] definition to set the buffer position before a [[PUT]].
|
|
|
|
|
|
{{PageExamples}}
|
|
''Example 1:'' Using LSET with a [[FIELD]] definition. Note: May create an empty (unchanged) file that can be deleted.
|
|
{{CodeStart}}
|
|
'' ''
|
|
{{Cl|OPEN}} "testfile.dat" FOR {{Cl|RANDOM}} AS #1 {{Cl|LEN}} = 15
|
|
{{Cl|FIELD}} 1, 6 {{Cl|AS}} a$, 9 {{Cl|AS}} other$
|
|
{{Cl|FIELD}} 1, 2 {{Cl|AS}} b$, 13 {{Cl|AS}} another$
|
|
{{Cl|LSET}} a$ = "1234567890"
|
|
{{Cl|LSET}} other$ = "1234567890"
|
|
{{Cl|PRINT}} a$, b$, other$, another$
|
|
{{Cl|CLOSE}} #1
|
|
|
|
{{CodeEnd}}
|
|
{{OutputStart}}
|
|
123456 12 123456789 3456123456789
|
|
{{OutputEnd}}
|
|
|
|
|
|
''Example 2:'' How LSET can define two different string length values in one statement.
|
|
{{CodeStart}}
|
|
|
|
{{Cl|TYPE}} ninestring
|
|
head {{Cl|AS}} {{Cl|STRING}} * 9
|
|
{{Cl|END TYPE}}
|
|
|
|
{{Cl|TYPE}} fivestring
|
|
head AS {{Cl|STRING}} * 5
|
|
{{Cl|END TYPE}}
|
|
|
|
{{Cl|DIM}} me {{Cl|AS}} ninestring, you {{Cl|AS}} fivestring
|
|
me.head = "ACHES NOT"
|
|
{{Cl|CLS}}
|
|
|
|
{{Cl|LSET}} you.head = me.head
|
|
{{Cl|PRINT}} "me.head: "; me.head
|
|
{{Cl|PRINT}} "you.head: "; you.head
|
|
{{CodeEnd}}
|
|
{{OutputStart}}
|
|
me.head: ACHES NOT
|
|
you.head: ACHES
|
|
{{OutputEnd}}
|
|
|
|
|
|
{{PageSeeAlso}}
|
|
* [[RSET]], [[RTRIM$]]
|
|
* [[FIELD]], [[TYPE]]
|
|
|
|
|
|
{{PageNavigation}}
|