Updated: September 27, 2011
Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012
Strings are sequences of characters that are used as texts, help lines, addresses, telephone numbers, and so on. To declare a string in X++, use the str keyword.
A string can hold an indefinite number of characters. If you know the absolute maximum of characters a string will hold, you can specify this in the variable declaration and force a truncation to the maximum length of the string.
Range and Precision
Declaring Strings
The declaration of strings is described in the following table.
|
String declaration |
= |
str [Typeoptions] Variable { , Variable } ; |
||
|
Typeoptions |
= |
[maxlength]
|
||
|
Variable |
= |
Identifier [option] |
||
|
Option |
= |
The Typeoptions specify an optional maximum length and a comparison scheme.
String Literals
String literals are characters that are enclosed in quotation marks (" ") and can be used where string expressions are expected. Here are some examples:
-
"Nothing"
-
"A"
-
"yiruyshfkjsadhfkasfhksafhask"
-
"Press any key now."
If you want the string to span more than one line, you need to precede it with an "@" character. For example:
str s = @"This is a very long string that may not fit onto a single line and so may span more than one line";
Caution