LEN - String Length

Help Contents

Introduction

Returns the number of characters in a string.

Syntax

Informal Syntax:

LEN( In )

Formal Syntax:

LEN( In:=expression )

Parameters

ParameterTypeDescription
InANY_STRINGThe string to take the length of.

The function is overloaded and accepts either the STRING or WSTRING type for the In parameter.

Return Value

The function LEN returns a UINT value representing the number of CHAR or WCHAR elements in the string In.

The return value can be larger than the number of characters you would see on a screen. A displayed code point might be encoded as multiple CHAR or WCHAR elements. For example, the Chinese character for home/room (屋) would be encoded in a STRING using three CHAR elements: 16#E5 16#B1 16#8B. The return value for this code point would be 3.

Examples

ExampleReturn Value
LEN('')UINT#0
LEN('Some Text')UINT#9
LEN(STRING#'屋')UINT#3 (see note below)
LEN("")UINT#0
LEN("Some Text")UINT#9
LEN(WSTRING#"屋")UINT#1

Note: The Chinese character for home/room (屋) is encoded in UTF-8 as three CHAR values: 16#E5 16#B1 16#8B. So the length of the string '屋' is 3.

Standards Compliance

IEC 61131-3 Second Edition: Table 29.1.

IEC 61131-3 Third Edition: Table 34.1.

Further Information

String Functions

To learn about other String Functions.

String Literals

To learn about string literals and the different types of encoding used.

Common Elements

To learn about other IEC 61131-3 Common Elements.

Glossary

For the meaning of terms used in Fernhill SCADA.