String (String, Widestring)
String is used to represent an array of characters in digital form, and can contain any character including Unicode.
Previously, String was regarded as a non-Unicode format data type, and WideString was used to support Unicode. Now that the String data type has full Unicode support, the WideString data type is superfluous.
Unicode is an international character encoding standard that provides a unique number for characters from different world languages, such as ç, è, ü, or ß.
Declaration: var myvariable : string;
var myvariable : widestring;
The default value of a String data type is empty which means that it contains no characters. A String can also be blank containing one or more spaces, but it cannot ever be null.
When entered into a script, a String is enclosed within single quotes such as the following example, so a single-quote character (') holds special significance that indicates the start and end of a String.
Value :=
'Afternoon. This is a string of characters!'
;
This poses a problem should you need to represent a single-quote or apostrophe within the string itself. To mitigate this issue and indicate to Statelake that the single-quote within the String is not a start or end indicator and should be ignored, enter it as two single-quotes within the String. It will be read as one single-quote only within the String.
For example to represent the string Hello. My name's Cameron, you would enter the following code, so that there are two single-quotes between the e and s resulting in the word name''s being written.
Value :=
'Hello. My name'
's Cameron'
;
Most SQL Databases also use a single quote to represent a String in an SQL statement. Statelake will correctly manage the conversion of single quotes when working with DB Definitions.
In cases where a double-quote is used as a significant indicator on a String, such as when double-quotes are used as start and end String field indicators within a comma-delimited file, then the double-quote is entered twice (““) within the String field itself so that it will be read as one double-quote only within the field itself.
However, it is common to write custom SQL statements within the Map script, and you should take care to use the correct quoting so the resulting SQL is correct.
Strings can be concatenated together with the + operator as illustrated here, to produce a single String that reads The value of myvariable is Hello World! .
procedure
ScriptEvent (
var
Value : variant);
var
myvariable :
string
;
begin
myvariable :=
'Hello World!'
;
loginfo(
'The value of myvariable is '
+myvariable);
end
But great care must be taken when adding number types to a String.
In the following example, the intention is to have a String with that has the contents The amount is $123.45. So the following code could be used to create this text.
MyFloatVariable :=
123.45
;
Value :=
'The amount is $'
+ MyFloatVariable;
However, if the code is ambiguous, the script engine may not know whether you want to concatenate the pieces or add the number, and it may become confused. And that confusion will result in an error - particularly if the number variable (in this case MyFloatVariable) is defined as a Variant data type.
The following code sets the number variable to a Variant type, but when executed does not generate a compiler error. See the Log entry below.
procedure
ScriptEvent (
var
Value : variant);
var
MyFloatVariable : variant;
var
thewholething :
string
;
begin
MyFloatVariable :=
123.45
;
thewholething :=
'The amount is $'
+ MyFloatVariable;
LogInfo(thewholething);
end
;

However, successful execution is pure luck. There is no guarantee that the script engine will not have an error and will execute correctly as above. Do not rely on the script engine behaving as you think it should!
So to mitigate any error or misinterpretation of the data, the best practice is to convert the variable containing 123.45 into a String. The value in the variable is then explicitly converted, as in the next example using the FloatToStr function.
For more information, please refer to Functions And Procedures.
MyFloatVariable :=
123.45
;
Value :=
'The amount is $'
+ FloatToStr(MyFloatVariable);
This conversion can then be successfully performed where the 123.45 is of Variant data type.
As stand-alone code, this translates into the following -
procedure
ScriptEvent (
var
Value : variant);
var
MyFloatVariable : variant;
var
thewholething :
string
;
begin
MyFloatVariable :=
123.45
;
thewholething := (
'The amount is $'
+ FloatToStr(MyFloatVariable));
end
;
Also refer to Memo for dealing with very large Strings.