String vs. Binary Data

A string in BDL represents a combination of a memory buffer and the length of the valid data within that buffer. For this reason, the string data type does not depend on a zero termination for its data. Due to the nature of this implementation, a BDL string can be interpreted as a zero-terminated sequence of characters (e.g., a string in C++ or as binary data with a specified length, no matter how many zeros exist within the data).

For backward compatibility reasons, a string is usually interpreted as a zero terminated sequence of characters (C++ string).

Example

transaction TMain
var
  s1 : string;
  s2 : string;
  s3 : string;
begin
  // s1 now holds the string "hello
  s1 := "hello"; "
  // s2 now holds also the string "hello"
  s2 := s1;
  // s3 now holds the concatenation of
  // s1 and s2, or "hellohello";
  s3 := s1 + s2;
end TMain;

When hex notation is used to specify a string, the data is automatically interpreted as binary data. However, if two BDL strings are concatenated with the ‘+’ operator, or if one string is assigned to another string, they will still be interpreted as strings.

Example

transaction TMain
var
  s1 : string;
  s2 : string;
  s3 : string;
begin
  // s1 now holds the binary data "\h110022"
  s1 := "\h110022";
  // s2 now holds the string "\h11"
  s2 := s1;
  // s3 now holds the string concatenation of
  // s1 and s2, or "\h1111"
  s3 := s1 + s2;
end TMain;

To change the way a string is interpreted, the bin() operator must be used. The bin() operator is allowed in conjunction with a string variable or a function call that returns a string. Using the previous example, if the bin() operator is used, the result is quite different.

Example

transaction TMain
var
  s1 : string;
  s2 : string;
  s3 : string;
begin
  // s1 now holds the binary data "\h110022"
  s1 := "\h110022";
  // s2 now holds the string "\h110022"
  s2 := bin(s1);
  // s3 now holds the binary concatenation of
  // s1 and s2, or "\h110022110022";
  s3 := bin(s1) + bin(s2);
end TMain;
Note: The bin() operator can be used in string assignments, concatenations, in string comparisons and in the actual parameters of function calls.