Welcome to the Creatures Wiki! Log in and join the community.
CHAR
Jump to navigation
Jump to search
CHAR is a CAOS command used for character-by-character string manipulation.
Contents
Usage
Syntax: CHAR str (string variable) index (int) char (int)
Sets the indexth character of str to char, where char is a the ASCII code for the required character. index=1 is the first character in the string.
Strings are fixed length, so you cannot address an index greater than STRL
Note that in CAOS 'x'
represents the numeric equivalent of the character x.
Syntax: CHAR str (string variable) index (int)
Returns, as an integer, the indexth character of str.
This is not the same as a string containing the character. For that, use SUBS str index 1.
Example
ROT13 (here with Docking Station):
sets va00 gnam setv va01 strl va00 loop addv va02 1 setv va03 char va00 va02 setv va04 0 doif va03 ge 'A' and va03 le 'Z' addv va04 1 endi doif va03 ge 'a' and va03 le 'z' addv va04 1 endi doif va04 eq 1 addv va03 13 doif va03 ge 91 and va03 le 103 subv va03 26 elif va03 ge 123 and va03 le 135 subv va03 26 endi char va00 va02 va03 endi untl va02 eq va01 outs va00 Qbpxvat Fgngvba