Skip to main content

trimRight

Short summary​

This method is used to remove the whitespace from the end of the string. It does not really remove it, it just decreases the string length.

Parameters​

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

Code​

Declaration​

METHOD PROTECTED trimRight
VAR_INPUT
(* start address of the string *)
stringAddress :POINTER TO BYTE;
END_VAR
VAR_IN_OUT
(* 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 :LINT;
END_VAR

Implementation​

RETURN(NOT trimString OR_ELSE stringAddress = 0 OR_ELSE stringLength <= 0);

character := stringLength;
WHILE(character >=0) DO
RETURN (NOT THIS^.isCharWhiteSpace(stringAddress[character := character-1]));
stringLength := stringLength-1;
END_WHILE