STRING_BEGIN

Top  Previous  Next

STRING_BEGIN is used to create raw strings. Raw strings still use the STRING data type, but are defined by surrounding the text with STRING_BEGIN and STRING_END instead of double quotes. This makes it possible to use special characters without having to escape them.

 

A raw string will consist of the contents of every line after the line with STRING_BEGIN, until it finds a line that starts with STRING_END.

It does not include the final linebreak before STRING_END.

 
No further text is allowed after STRING_BEGIN.

 

Note: A newline in the string follows the Windows convention and is composed of an CR (value 13) followed by LF (value 10).

 

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  str1         : STRING := STRING_BEGIN
This is the contents of the first string.
It can include both " and $ with no escaping.
To end the string, place STRING_END at the start of a new line as such:
STRING_END;
  str2         : STRING;
  str3         : STRING;
  str4         : STRING;
END_VAR;
 
PROGRAM test;
 
  str2 := STRING_BEGIN
Raw strings can be concatenated like any other strings:
"
STRING_END + str1 + "$"";
 
  str3 :=
STRING_BEGIN
STRING_BEGIN does not have to be on the same line as the assignment.
This can sometimes help with the readability.
To end the string, STRING_END *must* be at the start of the line.
 STRING_END does not work, as there is a space before it.
STRING_END;
 
  str4 :=
string_begin
STRING_BEGIN and STRING_END do not have to use upper case letters.
sTrInG_eNd;
 
 
BEGIN
 
END;
 
END_PROGRAM;