variable in text
-
JuEdir -
February 7, 2020 at 12:40 PM -
Thread is Unresolved
-
-
yes, string manipulation can be done in different ways
-
You will want to use SWrite function, who's use is described in CRead/CWrite manual.
-
In general, any variable located in $CONFIG.DAT can be altered during program executation, by the program. Many System Variables (like $SOFTx_END) can also be written to by a program, but others are write-protected for safety.
String variables are, technically, arrays of type CHAR. SWRITE can be used to manipulate them, or you can iterate through the array with a FOR loop index and directly assign each character.
-
yup, SWrite allows inserting and formating of values into a string. there are string functions too (copy, add) as well. but one may choose to manipulate the values directly since they are just arrays.
-
-
exactly
"0" = 48 (0x30)
"1" = 49 (0x31)
"2" = 50 (0x32)
etc.
so if we add 48 to counter variable with value 0-9, it will produce ASCII characters "0"-"9"
this is also how upper and lower case is converted etc. (basicaly just set or reset bit if character is on come range)
also worth mentioning - there are two types of strings commonly used:
form1: first byte is string length and tells how many of characters follow. this limits number of characters to 256 per string.
form2: zero-terminated strings. string can be much longer and it is considered finished when first 0 values is encountered.
the zero or null-terminated string is used internally but KRL still treats strings as character arrays.
so if you do something like
DECL CHAR s[10]
s[]="panic"
halt ; display value and shown content is "panic"
s[4]=0 ; replace 4th character with zero to shorten the string
halt ; display value and shown content is "pan"
however.... that is just what is displayed. this is not a real string.
you can still read/write values of s[4] and s[5] since they ARE initialised. but s[6..10] are not.
however checking string length would return value 3 which matches "pan".
so yeah... there are some quirks and inconsistencies like that all over the place if you really look.