getStringLength
Short summary
this methods returns the length of a null-terminated string in bytes
Attention: All strings are handled as null-terminated byte streams.
:return: length of the string
- Return type:
UDINT
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| stringAddress | POINTER TO BYTE | Start address of the string for which the length is to be determined | input |
Code
Declaration
METHOD PROTECTED getStringLength :UDINT
VAR_INPUT
(* Start address of the string for which the length is to be determined *)
stringAddress :POINTER TO BYTE;
END_VAR
VAR CONSTANT
(* the end of string marker *)
END_OF_STRING :BYTE := 16#00;
END_VAR
Implementation
getStringLength := 0;
RETURN(stringAddress = 0);
WHILE (stringAddress[getStringLength] <> END_OF_STRING) DO
getStringLength := getStringLength + 1;
END_WHILE