A STRING is padded with spaces
A CSTRING is null terminated (where a null is a ‘<0>’)
MyString STRING(4)
MyCSTRING CSTRING(4)
CODE
MyString = 'Hi'
MyCSTRING = 'Hi'
If you looked at the bytes, you’d see
MyString has ‘H’, ‘i’, ‘<32>, ‘<32>’ ! note: <32> is a space
MyCstring has ‘H’, ‘i’,’<0>’, UNDEFINED
Also note that the MyCstring(4) can only hold 3 characters as the ‘<0>’ is counted as one
Whereas the MyString(4) can hold 4 characters
Nearly all APIs using CSTRING
A benefit of CSTRINGs is that you don’t need to constantly clip them
LongerCString CSTRING(16)
CODE
MyCstring = 'Hi'
MyCstring = MyCstring & ' There'
Now MyCstring will have ‘Hi There’ followed by a ‘<0>’ and then undefined bytes
On the other hand:
LongerString STRING(15)
CODE
LongerString = 'Hi'
LongerString = LongerString & ' There'
The problem here is that the first line set LongerString to ‘Hi ’
‘Hi’ & ALL(’<32>’,13)
So the 2nd line makes no change, as it just overflows the variable
Instead you need to write
LongerString = CLIP(LongerString) & ' There'
Now you can put spaces into a CSTRING
So if you write
MyCstring CSTRING(16)
MyString STRING(15)
CODE
MyString = 'Hi' ! <-- remember this will pad with spaces
MyCString = MyString ! <-- copied in the spaces