Skip to main content

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

NameTypeCommentKind
stringAddressPOINTER TO BYTEstart address of the stringinout
stringLengthUDINTlength of the string stringAddressinout
trimStringBOOLTRUE means remove the whitespace, FALSE means do not remove the whitespaceinput

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;