Difference between revisions of "RSET"

From QB64 Wiki
Jump to navigation Jump to search
Line 9: Line 9:
  
  
''Syntax:'' RSET string = stringexpression
+
''Syntax:'' RSET stringvariable = stringexpression
  
  

Revision as of 00:42, 7 October 2009

RSET right-justifies a string according to a string expression. Spaces are used to pad the extra positions in the string. If the stringexpression is larger than the string then it is truncated.


RSET can be used with strings related to the FIELD statement for reasons I don't really understand since I seldom use FIELD (any help here would be appreciated), the QuickBASIC help-system has this to say;


RSET - a string processing statement that moves data from memory to a random-access file buffer (in preparation for a PUT statement) or right-justifies the value of a string in a string variable.


Syntax: RSET stringvariable = stringexpression


string and stringexpression can be of different lengths in which the stringexpression is right-justified or truncated accordingly.


If the stringexpression is larger than the fixed-length string then it is truncated from the right (in both LSET and RSET)


Example:

CLS
DIM thestring AS STRING * 10
PRINT "12345678901234567890
RSET thestring = "Hello!"
PRINT thestring
anystring$ = SPACE$(20)
RSET anystring$ = "Hello again!"
PRINT anystring$
RSET thestring = "This is more than ten characters"
PRINT thestring


Results:

12345678901234567890
   Hello!
     Hello Again!
This is mo


Explanation:

Notice how "Hello!" ends at the tenth position, that is because the length of the string is 10, when we used SPACE$(20) the length of anystring$ became 20 so "Hello Again!" ended at the 20'th position. That is what is meant with being right-justified. Ignore the "-" they are used to represent spaces.

The last line "This is mo" is truncated as it didn't fit into the string whos length was only 10 characters.


See also: LSET, LTRIM$, RTRIM$, FIELD, PUT


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage