Programming for experts
P.
109 of 349
String concatenation with
different length
Concatenation of same size strings
Concatenation of two strings and
allocation on a bigger string
Concatenation of two strings and
allocation to a smaller string
Prevent data loss:
#ifdef OSX
string=convert(encode($Hällo °C$,$utf-8$c14,$iso8859-15$c14),$$c14)
#endif
#ifdef WIN
string=$Hällo °C$c14
#endif
Now EibStudio is not able to display the telegram e.g. in OSX because "ä" in UTF-8 would be an
another character code as on the KNX
TM
bus. On bus the Enertex® EibPC sends the correct code,
which can easily be shown based on the raw data.
In string processing is often resorted to the concatenation i.e. the “concateantion” of strings.
Thus e.g. in the code
s1=$Hallo $c1000
s2=$Welt$c1000
s3=s1+s2
the string
s3
will have the content
Hello World.
The data type control in the EibParser ensures that
s3
is of type c1000. The EibParser ensures that the concatenation can record the size of the longest
string , in the present case are for
s1+s2
1000 Bytes.
s3
are assigned as a result of the
concatenation
s1+s2
1000 Bytes.
If 950 bytes of data already available in
s2
and in
s1
in turn is 90 bytes then 40 bytes are in the
concatenation “lost” because only
s3
can max. hold 1000 Bytes.
The following code is to be sonsidered as well:
s1=$Hallo $c1000
s2=$Welt$c1000
s3=$$c2000
if htime(10,00,00) then s3=s1+s2 endif
Again the concatenation is
s1+s2
the length of 1000 Bytes, as they are composed out of two 1000
byte-strings. The assignment to the 2000 bytes long
s3
ovvurs only after the concatenation. However
as already the concatenation operation has limited the length up to 1000 bytes here bytes can get
“lost”.
This is in the following code different:
s1=$Hallo $c1000
s2=$Welt$c1000
s3=$$c200
if htime(10,00,00) then s3=s1+s2 endif
Again the concatenation is
s1+s2
the length of 1000 bytes, as they are composed out of two 1000
byte strings. The assignment of the 200 bytes long
s3
occurs only as a result of the concatenation:
First the concatenation operation
s1+s2
limited the length up to 1000 bytes, allocating limited to
s3
its length to 200 bytes, so assuming, where 800 bytes of data „lost”.
If the concatenation
s1+s2
in no case lose data, a dummy variable has to be introduced:
s1=$Hallo $c1000
s2=$Welt$c1000
s3=$$c2000
dummy=$$c2000
if htime(10,00,00) then s3=s1+s2+dummy endif
This ensures that
s1+s2+dummy
2000 bytes can hold as a result. Therefore the concatenation will
deliver 2000 bytes to
s3
as a result.
HandbuchEibPC_USA-30.odt, 2017-05-11
Enertex
®
Bayern GmbH - Erlachstraße 13 - 91301 Forchheim - [email protected]