AX / D365FO – Substring function in X++ #d365fo #ax #msdyn365fo

To retrieve part of a string in X++ you can use substr() function.

This is the function definition

str subStr(str _text, int _position, int _number)

Parameters

ParameterDescription
_textThe original string.
_positionThe position in the original string where the part to retrieve begins.
_numberA signed integer that indicates the direction and number of positions to retrieve from the original string. If a minus sign precedes _number, the system selects the substring backward from the specified position.

Here are some examples on how to use it :

subStr("ABCDEFGHIJ",3,5);   //Returns the string "CDEFG".
subStr("ABCDEFGHIJ",7,-4);  //Returns the string "DEFG".
subStr("abcdef",2,99)       //Returns the string "bcdef".
subStr("abcdef",2,3)        //Returns the string "bcd".
subStr("abcdef",2,-3);      //Returns the string "ab".

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s