AX / D365FO – Important String functions in X++

Substring Function

 static void subStr(Args _args)

{
str s;
real r;
;
r = strLen("jones@gmail.com");
s = subStr("jones@gmail.com",5, 2);
info(strFmt("s=%1 and r=%2",s,r));

}

String Comparison 

static void strCmp(Args _args)

{
int i=2;
str s1,s2;
;
s1="string 1";
//s2="string 1";
s2="string 2";
i = strCmp(s1,s2);
if (0 == i)
{
info(strFmt("s1 and s2 are the same"));
}
else
{
info(strFmt("s1 and s2 are different"));
}

}

String Deletion

static void strDel(Args _args)

{
str s;
;
s = strDel("Jitendrakumar", 5, 2);
info(strFmt(s));

}

Find characters in string

static void strFind(Args _args)

{
int i;
;
i = strfind("jitendrakumar", "jit", 0, 3);
if (1 == i)
{
info(strFmt("Characters are found in string"));
}
else
{
info(strFmt("Characters are NOT found in string"));
}
}

String format

static void strfmt(Args _args)

{
str s1 ="testing";
int s2 = 2;
real s3 =4.56;
str s;
;
s = strfmt("string =%1,Integer = %2, Real = %3, ", s1,s2,s3);
info( s);

}

Length of string

static void strLen(Args _args)

{
int i;
;
i = strLen("jitendra");
info(strFmt("i=%1",i));
}

Convert string in lower case

static void strLwr(Args _args)

{
str l;
;
l = strLwr("JITENDRA");
info(strFmt("l=%1",l));

}

Convert string in upper case

static void strUpr(Args _args)

{
str u;
;
u= strUpr("jitendra");
info(strFmt("u=%1",u));

}

Repetition of string 

            static void strRep(Args _args)

{
str r;
;
r = strRep("xyz ", 5);
print(strFmt("r=%1",r));

}

Convert date into string in x++

        static void systemDateGet(Args _args)

{
date d;
str d1,d2,d3 ;
;
d = systemdateget();
d1 = date2str(d,123,2,-1,2,-1,4);
d2 = date2str(d,231,2,-1,2,-1,2);
d3 = date2str(d,321,2,-1,2,-1,4);

print(strFmt("dates are %1,%2,%3,%4",d,d1,d2,d3));

}

Leave a comment