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:
| Sequence | Valid in | Result |
|---|---|---|
$$ | STRING, WSTRING | Literal $ |
$' | STRING | Literal ' |
$" | WSTRING | Literal " |
$L, $l, $N, $n | STRING, WSTRING | Line feed (\n) |
$R, $r | STRING, WSTRING | Carriage return (\r) |
$T, $t | STRING, WSTRING | Horizontal tab (\t) |
$P, $p | STRING, WSTRING | Form feed (\x0C) |
$hh | STRING | Byte with hex value hh (exactly 2 hex digits) |
$hhhh | WSTRING | UTF-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