Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

How to get particular words from group of sting value

Posted on by 562

Dear All,

I am getting one sting output  like this,

"8D8hZUgfk_NaqgawkRO5rC00xfHPwSSC3pMDxNX1GDhKedghSbVh8tTKivtcbz-VXmVFbKqW1m8YDAKJ5BCkXqb3F8RsGc2UdoPCGrk5H4","token_type":"TXT","expires_in":TOS"

 from the output ,I need only "token_type":"TXT",How i can get this particular word from the output 

BR,

Tony 

*This post is locked for comments

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: How to get particular words from group of sting value

    It can be done in many ways. The string seems to be JSON, therefore deserializing it to an object or a map sounds like the most natural approach. Then you'll simply check the value of "token_type".

    You could also split the string by comma with strSplit() and then either take the second element (if the order is fixed and the token can't contain comma) or then one starting with "token_type". Yet another solution would be using regular expressions. I would prefer handling it as JSON, though.

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to get particular words from group of sting value in ax 2012

    Ok, try this:

    static void Job174(Args _args)
    {
        str text = '{"access_token":"9OV9Xk-PSQqYY6OKGoJRyj5O7dIg-71PCa3-kS_h3Ayp1vNEe-D-ZMneYr9RvX7XNx9OdnvkG6141GLYHMr23RzZ2FyeqJu9xfDaYR193JfqQ_cI0JXbgo1zbeXigD3gDKX-QfgbttYhf8DkCDk_FtF2KSG-abgI69gjZOYZ2UToSAQ0fmuxccf2x70pUQKN_dnLbor2QiyW93eGLVMSVJD1rk6X37GBj_diGjZHIKc","token_type":"TXT","expires_in":86399}';
        str text2;
        int firstComma, secondComma;
        
        firstComma  = strFind(text, "," , 1, strLen(text)) + 1;
        secondComma = strFind(text, ",", firstComma, strLen(text));
        
        text2 = subStr(text, firstComma, secondComma - firstComma); 
        text2 = strRem(text2, '"');
        
    
        info(text2);
    }


  • TonyAx Profile Picture
    TonyAx 562 on at
    RE: How to get particular words from group of sting value in ax 2012

    Hi Rustem Galiamov,

    Thanks for replay its very use for me,But sorry now only i noted that real output below like this from that only ,I need token_type:TXT  ,

    {"access_token":"9OV9Xk-PSQqYY6OKGoJRyj5O7dIg-71PCa3-kS_h3Ayp1vNEe-D-ZMneYr9RvX7XNx9OdnvkG6141GLYHMr23RzZ2FyeqJu9xfDaYR193JfqQ_cI0JXbgo1zbeXigD3gDKX-QfgbttYhf8DkCDk_FtF2KSG-abgI69gjZOYZ2UToSAQ0fmuxccf2x70pUQKN_dnLbor2QiyW93eGLVMSVJD1rk6X37GBj_diGjZHIKc","token_type":"TXT","expires_in":86399}

    please give any solution on this.

    BR

    Tony

  • Suggested answer
    Rustem Galiamov Profile Picture
    Rustem Galiamov 8,072 on at
    RE: How to get particular words from group of sting value in ax 2012

    Hi Tony!

    You should use str functions.


    static void Job174(Args _args) { str text = "8D8hZUgfk_NaqgawkRO5rC00xfHPwSSC3pMDxNX1GDhKedghSbVh8tTKivtcbz-VXmVFbKqW1m8YDAKJ5BCkXqb3F8RsGc2UdoPCGrk5H4,token_type:TXT,expires_in:TOS"; str text2; int firstComma, secondComma; firstComma = strFind(text, "," , 1, strLen(text)) + 1; secondComma = strFind(text, ",", firstComma, strLen(text)); text2 = subStr(text, firstComma, secondComma - firstComma); info(text2); }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans