mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-31 14:40:15 +00:00
54 lines
2.1 KiB
Text
54 lines
2.1 KiB
Text
|
The '''RIGHT$''' function returns a set number of characters in a [[STRING]] variable starting from the end and counting backwards.
|
||
|
|
||
|
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
:: 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 1:'' Getting the right portion of a string value such as a person's last name.
|
||
|
{{CodeStart}} '' ''
|
||
|
name$ = "Tom Williams"
|
||
|
|
||
|
Last$ = {{Cl|RIGHT$}}(name$, {{Cl|LEN}}(name$) - {{Cl|INSTR}}(name$, " ")) 'subtract space position from string length
|
||
|
|
||
|
{{Cl|PRINT}} Last$ '' ''
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}Williams {{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 2:'' Adding the leading zero in single digit [[HEX$]] values using RIGHT to take the right two hexadecimal string digits.
|
||
|
{{CodeStart}} '' ''
|
||
|
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32) '32 bit screen modes ONLY!
|
||
|
red = 255
|
||
|
green = 0
|
||
|
blue = 128
|
||
|
|
||
|
Color32 red, green, blue
|
||
|
{{Cl|PRINT}} "Colored text"
|
||
|
|
||
|
{{Cl|SUB}} Color32 (R, G, B)
|
||
|
R = R {{Cl|AND (boolean)|AND}} {{Cl|&H}}FF: G = G {{Cl|AND (boolean)|AND}} {{Cl|&H}}FF: B = B {{Cl|AND (boolean)|AND}} {{Cl|&H}}FF ' limit values to 0 to 255
|
||
|
hexadecimal$ = "{{Cl|&H}}FF" + {{Cl|RIGHT$}}("0" + {{Cl|HEX$}}(R), 2) + {{Cl|RIGHT$}}("0" + {{Cl|HEX$}}(G), 2) + {{Cl|RIGHT$}}("0" + {{Cl|HEX$}}(B), 2)
|
||
|
{{Cl|PRINT}} hexadecimal$
|
||
|
{{Cl|COLOR}} {{Cl|VAL}}(hexadecimal$)
|
||
|
{{Cl|END SUB}} '' ''
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}'''{{text|&HFFFF0080|white}}'''
|
||
|
'''{{text|Colored text|#FF0080}}'''{{OutputEnd}}
|
||
|
: ''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.
|
||
|
|
||
|
|
||
|
''See also:''
|
||
|
* [[LEFT$]], [[MID$]]
|
||
|
* [[LTRIM$]], [[RTRIM$]]
|
||
|
* [[INSTR]], [[HEX$]]
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|