CreateString (FUN)¶
FUNCTION CreateString : IString
Returns a IString instance placed in the memory area given by the parameters.
Example for a IString instance with a capacity of minimal 80 byte:
sValue : STRING(50) := UTF8#'CØD€šŸŠ ïß värÿ çôõl';
udiCapacity : UDINT; // Capacity of the new String
axwMemory : ARRAY[0..(SIZEOF(STR._UTF8String)+80) / SIZEOF(__XWORD)] OF __XWORD;
itfString : STR.IString := STR.CreateString(ADR(axwMemory), SIZEOF(axwMemory), ADR(sValue), udiStrSize=>udiCapacity);
Note
The size of the memory area should be a multible of
SIZEOF(__XWORD)
.The last byte of this memory area is reserved for the final NULL byte.
Therefore,
udiCapacity
represents the practical amount of memory available.Please take a look to the function blocks in the Library “Generic String Base”
You can use the
GSB.UTF8String
function block, which performs this task in a much more convenient way- InOut:
Scope
Name
Type
Initial
Comment
Return
CreateString
Input
pbyMemory
POINTER TO BYTE
Pointer to the first byte of the memory.This address should aligned to a__XWORD
boundary!udiMemSize
UDINT
Size of the allocated memory for the string.This also includes the memory for the _UTF8String instance.If e.g. an 80 byte string is required than memory size would beSIZEOF(STR._UTF8String) + 80
psValue
POINTER TO BYTE
0
optional address of a utf-8 encoded, NULL terminated byte array (string), used as inital value
Output
udiStrSize
UDINT
The capacity in bytes of the new IString instance
eErrorID