Hello guys,
Does someone here knows the difference between String & CString in Clarion?
Thx.
Hello guys,
Does someone here knows the difference between String & CString in Clarion?
Thx.
I have to say @RamonBoorges, you first place to look for this sort of thing will be the Clarion Help. The section on Simple Data Types
will give you a full break down of all the different ones for Clarion. Was it something specific about the differences you were after like what are the practical differences when using STRING
vs CSTRING
or do you mean the technical differences between the data types?
I’ll take a look at the Clarion Help. I didn’t know that in the Clarion Help I can see this kind of stuff.
STRING creates white spaces after your string. For example STRING(20) stores like
“HELLO WORLD!..”
But CSTRING cuts the string after it finishes like
“HELLO WORLD!”
They works like SQL char(20) and varchar(20) variables.
If you use STRING, database size will be bigger and you will need to use CLIP when you join different STRING variables.
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