From QB64 Wiki
Revision as of 01:36, 19 October 2011 by imported>Clippy
Jump to navigation Jump to search

The RIGHT$ function returns a set number of characters in a STRING variable starting from the end and counting backwards.


RIGHT$(stringvalue$, numberofcharacters%)

  • The string value can be any string of ASCII characters as a string variable.
  • If the number of characters exceeds the string length(LEN) the entire string is returned.
  • Number of characters cannot be a negative value.
  • RIGHT$ returns always start at the last character of the string, even if a space. RTRIM$ can remove ending spaces.

Example: Getting the right portion of a string value such as a person's last name.

name$ = "Tom Williams" Last$ = RIGHT$(name$, LEN(name$) - INSTR(name$, " ")) 'subtract space position from string length PRINT Last$


Example 2: Adding the leading zero in single digit HEX$ values using RIGHT to take the right two hexadecimal string digits.

SCREEN _NEWIMAGE(640, 480, 32) red = 255 green = 0 blue = 128 Color32 red, green, blue PRINT "Colored text" SUB Color32 (R, G, B) R = R AND &HFF: G = G AND &HFF: B = B AND &HFF ' limit values to 0 to 255 COLOR VAL("&HFF" + RIGHT$("0" + HEX$(R), 2) + RIGHT$("0" + HEX$(G), 2) + RIGHT$("0" + HEX$(B), 2)) END SUB

Note: When a single digit is returned the resulting value will have the leading zero added. Otherwise it is ignored.

See also:

Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page