Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Get last 2 characters ...
Finance forum
Answered

Get last 2 characters of a string

Posted on by 99
Hi,
 
I have to get last 2 characters of a string using X++ code.
Eg: If my inputStr = 'QWERTY'
then i should get my outputStr = TY
 
I tried the below code but it doesn't seem to work, can someone help me 
        str InputString             = 'QWERTY';
        str OutputString          = subStr(warehouseString, (StrLen(InputString)-2), -2);
 
If my input string changes to POWER004 then my output string should be 04, can someone help me with the correct code.
  • Verified answer
    CU02071804-0 Profile Picture
    CU02071804-0 99 on at
    Get last 2 characters of a string
            str InputString             = 'QWERTY';
            str OutputString          = subStr(warehouseString, (StrLen(InputString)-1), 2);
     
    The above code will return the last 2 characters of the Input string.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans