Strings

String constants are bound with double quotes ("). String constants can exceed line boundaries using the escape sequence "\" (backslash). Any character is a valid character in a string constant. To use a double quote inside a string, you must place a backslash in front of the double quote (\"). To use a backslash inside a string, you must write two backslashes (\\). Multiple string constants bound with double quotes and separated only with white space are treated as one string constant.

This data type represents an object consisting of a memory buffer for holding character data and its length. The memory buffer is always equal or larger than the character data represented by a string variable. You can declare the initial size of the memory buffer, which corresponds to the number of characters a size of the memory buffer, which corresponds to the number of characters a variable of type string can hold without resizing its buffer. During its use, the memory buffer can grow and shrink on demand

If you omit the length specification, the memory buffer is automatically pre-allocated to hold 254 characters including a termination character. A string is terminated by a null character (\0). However, if binary data is stored in the string variable several null characters may occur. The string variable knows the length of the data it is holding.

The elements of a string (single characters) can be referenced by an index beginning at one (1) for the first character in the string.

The string data type is as well designed to hold binary data. If binary data is assigned to a string variable the real length of the binary data is set accordingly.

A string variable implements the so-called NULL-pointer semantics, which means that it can differentiate between an empty string and a null string. A null string can be interpreted as string variable referencing no string object (null). An Empty string is a variable that references a string object, which holds a string without characters (""). In order to investigate or manipulate the current state of a string variable several string manipulation functions are provided.

注: Any string variable, which is declared in any var section is initialized to its declared initial memory buffer size and represents an empty string (not null).

Syntax

string = '"' char { char } '"'.

BDL Example

The following string constants are valid:

dcltrans
  transaction TMain
var
  sString1 : string(40);
  sString2 : string(100);
  sString3 : string;

  sBin1 : string;
  sBin2 : string;
  sBin3 : string;
begin
  sString1 := "This is a string";
  sString2 := sString1;
  sString3 := "Hello" + sString1;

  sBin1 := "\h11223300445566";
  sBin2 := sBin1;
  sBin3 := "Hello " + sBin2 + "\h20";
end TMain;

SQL Example

String constants used in SQL commands are enclosed in single quotes (')

SELECT * FROM article WHERE name = 'pants'