Skip to main content

RightOfAnyString

Short summary

This function edits an AnyString, so only the count of size rightmost characters of the string remain. If size is greater than the length of string, the string is unchanged.

It returns the new size of the string (Utf8: in byte, Utf16: in words).

Attention: All strings are handled as null-terminated byte streams

Example:

myString 			:WString(10) := "Test";
lengthOfMyString :UDINT := 4;
------------------
RightOfAnyString(
stringAdress := ADR(myString),
length := 3,
newStringLength => lengthOfMyString
); // myString will be "est" with length 3
  • Return type: UDINT

Parameters

NameTypeCommentKind
stringToHandleANY_STRINGstring to get the right chars ofinput
lengthUDINTcount of characters in in new substringinput
normalizeStringBOOLnormalize the string before creating subtringinput
newStringLengthUDINTnew length of the string in bytesoutput

Code

Declaration

FUNCTION RightOfAnyString: UDINT
VAR_INPUT
(* string to get the right chars of *)
stringToHandle :ANY_STRING;
(* count of characters in in new substring *)
length :UDINT;
(* normalize the string before creating subtring *)
normalizeString :BOOL := TRUE;
END_VAR
VAR_OUTPUT
(* new length of the string in bytes *)
newStringLength :UDINT := 0;
END_VAR

Implementation

RETURN((stringToHandle.pValue = 0) OR stringToHandle.diSize <= 0);

CASE stringToHandle.TypeClass OF
__SYSTEM.TYPE_CLASS.TYPE_STRING:
RightOfUtf8String(
stringAddress := stringToHandle.pValue,
length := length,
normalizeString := normalizeString,
newStringLength => newStringLength
);
RightOfAnyString := newStringLength;
__SYSTEM.TYPE_CLASS.TYPE_WSTRING:
RightOfUtf16String(
stringAddress := stringToHandle.pValue,
length := length,
normalizeString := normalizeString,
newStringLength => newStringLength
);
RightOfAnyString := newStringLength;
ELSE
; // do nothing
END_CASE