trimLeft
Short summary
This method is used to remove the whitespace from the start of the string. It does not really remove it, it just moves the start address and decreases the string length
Parameters
| Name | Type | Comment | Kind |
|---|---|---|---|
| stringAddress | POINTER TO BYTE | start address of the string | inout |
| stringLength | UDINT | length of the string stringAddress | inout |
| trimString | BOOL | TRUE means remove the whitespace, FALSE means do not remove the whitespace | input |
Code
Declaration
METHOD PROTECTED trimLeft
VAR_IN_OUT
(* start address of the string *)
stringAddress :POINTER TO BYTE;
(* length of the string ``stringAddress`` *)
stringLength :UDINT;
END_VAR
VAR_INPUT
(* ``TRUE`` means remove the whitespace, ``FALSE`` means do not remove the whitespace *)
trimString :BOOL;
END_VAR
VAR
(* index of the current character *)
character :UDINT;
(* counter of the whitspace characters *)
whitespaceCount :UDINT;
(* highest search index in the string *)
maxSearchIndex :UDINT;
END_VAR
Implementation
RETURN (NOT trimString OR_ELSE stringAddress = 0 OR_ELSE stringLength <= 0);
maxSearchIndex := stringLength - 1;
FOR character := 0 TO maxSearchIndex DO
IF NOT (THIS^.isCharWhiteSpace(stringAddress[character])) THEN
EXIT;
END_IF
whitespaceCount := whitespaceCount + 1;
END_FOR
stringAddress := stringAddress + whitespaceCount;
stringLength := stringLength - whitespaceCount;