次の方法で共有


Strings

Applies To: Microsoft Dynamics AX 2012 R3, 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

Strings are unlimited in length unless a length is specified in the declaration.

Declaring Strings

The declaration of strings is described in the following table.

String declaration

=

str [Typeoptions] Variable { , Variable } ;

Typeoptions

=

[maxlength]

Caution

X++ that is compiled into .NET Framework common intermediate language (CIL) code ignores the [maxlength] specification. For information about how to detect cases where strings are truncated due to a [maxlength] specification during run time, read about the logstrtrunc option in Client configuration commands.

Variable

=

Identifier [option]

Option

=

Arrayoptions | initialization

The Typeoptions specify an optional maximum length and a comparison scheme.

 
//Dynamic string of unlimited length
str indefiniteString;

//String with a maximum of 64 characters, initialized to "A"
str 64 maxLengthString = "A";

//Array of 100 strings
str 30 hundredStrings[100];

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";

Automatic Conversion

There is no automatic conversion of strings.

Using Strings in Expressions

You can use strings in logical expressions, such as comparisons. You can also concatenate strings by using the + operator, as follows:

    void myMethod()
    {
        // Two strings are declared and initialized
        str a="Hello", b="World";
        ;
     
        // The concatenation of a, " " and b is printed in a window.
        print a+" "+b;
        pause;
    }

Overview of Strings

Keyword

str

Size of data type

Dynamic or fixed length

Scope of data type

Unlimited

Default value

"" (empty)

Implicit conversions

None

Explicit conversions

str2int, str2int64, int2str, str2num, num2str, str2date, date2str

See also

Data Types in X++

Variables

str2Int Function

str2Int64 Function

int2Str Function

str2Num Function

num2Str Function

str2Date Function

date2Str Function

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.