By assigning a fixed-length string, the copying unexpectedly stops at the first appearance of chr(0) in the fixed-length string and the rest is ignored.
Example:
Dim s1 As String * 10, s2 As String * 15, s As String
Mid(S1, 1) = "0"
Mid(s1, 10) = "9"
Print "'"; : Print s1; : Print "'"
Print
s2 = s1
Print "'"; : Print s2; : Print "'"
s = s1
Print "'"; : Print s; : Print "'"
Sleep
Output:
'0 9'
'0 '
'0'
A workaround is to use the substring function Mid(), even without explicitly pass the substring length as parameter:
Dim s1 As String * 10, s2 As String * 15, s As String
Mid(S1, 1) = "0"
Mid(s1, 10) = "9"
Print "'"; : Print s1; : Print "'"
Print
s2 = s1
Print "'"; : Print s2; : Print "'"
s = s1
Print "'"; : Print s; : Print "'"
Print
s2 = Mid(s1, 1)
Print "'"; : Print s2; : Print "'"
s = Mid(s1, 1)
Print "'"; : Print s; : Print "'"
Sleep
Output:
'0 9'
'0 '
'0'
'0 9 '
'0 9'
Therefore the first behavior (diect assignment) could probably be improved.
Referring to forum, from the post:
http://www.freebasic.net/forum/viewtopic.php?p=202720#p202720
Two other different behaviors with a fixed-length string:
1) declaration with initializer (with literals & Chr(0))
'Chr(0)' is taken into account and the following characters:
Output:
2) assignment (with literals & Chr(0))
'Chr(0)' is skipped but not the following characters:
Output:
The new definition of the 'STRING*N' datatype (since fbc 1.20.0) solves the problem.