RIGHT$ - mkilgore/QB64pe GitHub Wiki
The RIGHT$ function returns a set number of characters in a STRING variable starting from the end and counting backwards.
- RIGHT$(stringvalue$, numberofcharacters%)
- The stringvalue$ can be any string of ASCII characters as a STRING variable.
- The numberofcharacters INTEGER value determines the number of characters to return from the right end of the string.
- If the number of characters exceeds the string length(LEN) the entire string is returned.
- RIGHT$ returns always start at the last character of the string, even if a space. RTRIM$ can remove ending spaces.
- Number of characters cannot be a negative value.
Last$ = RIGHT$(name$, LEN(name$) - INSTR(name$, " ")) 'subtract space position from string length PRINT Last$ '' '' |
Williams |
Example 2: Adding the leading zero in single digit HEX$ values using RIGHT to take the right two hexadecimal string digits.
Color32 red, green, blue PRINT "Colored text" SUB Color32 (R, G, B) R = R AND (boolean) &HFF: G = G AND (boolean) &HFF: B = B AND (boolean) &HFF ' limit values to 0 to 255 hexadecimal$ = "&HFF" + RIGHT$("0" + HEX$(R), 2) + RIGHT$("0" + HEX$(G), 2) + RIGHT$("0" + HEX$(B), 2) PRINT hexadecimal$ COLOR VAL(hexadecimal$) END SUB '' '' |
'''<span style="color:white;">&HFFFF0080</span>''' '''<span style="color:#FF0080;">Colored text</span>''' |
- Note: When a single hexadecimal digit is returned the resulting value will need the leading zero added. Otherwise the hexa- decimal value created will have a byte missing from the value. EX: Color &HFF000000 is valid while &HFF000 is not.
Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page