Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E124: Invalid escape sequence in string literal

This error occurs when a string literal contains a $-escape sequence that is not valid per IEC 61131-3.

Valid escape sequences are:

SequenceValid inResult
$$STRING, WSTRINGLiteral $
$'STRINGLiteral '
$"WSTRINGLiteral "
$L, $l, $N, $nSTRING, WSTRINGLine feed (\n)
$R, $rSTRING, WSTRINGCarriage return (\r)
$T, $tSTRING, WSTRINGHorizontal tab (\t)
$P, $pSTRING, WSTRINGForm feed (\x0C)
$hhSTRINGByte with hex value hh (exactly 2 hex digits)
$hhhhWSTRINGUTF-16 code unit with hex value hhhh (exactly 4 hex digits)

Examples

Unrecognised escape character

FUNCTION main : DINT
VAR
    s : STRING[20] := 'test$Qtest';   (* $Q is not a valid escape *)
END_VAR
    main := 0;
END_FUNCTION

Incomplete hex escape

FUNCTION main : DINT
VAR
    s : STRING[10] := '$A';       (* STRING needs exactly 2 hex digits: e.g. $41 *)
    w : WSTRING[10] := "$004";    (* WSTRING needs exactly 4 hex digits: e.g. $0041 *)
END_VAR
    main := 0;
END_FUNCTION

Trailing dollar sign

FUNCTION main : DINT
VAR
    s : STRING[10] := 'hello$';   (* '$' at end of literal has nothing to escape *)
END_VAR
    main := 0;
END_FUNCTION