SBX - Search With Button

SBX - Forum Post Title

How to remove first word from string

Microsoft Dynamics AX Forum

Akbarpasha asked a question on 13 Jun 2018 7:52 PM

Question Status

Suggested Answer

How to remove first word from string in AX 2012  run time, 

First can be of any length, requirement is to remove or delete the first word of the string dynamically,

we have string function but haven't found any function that removes/deletes first word from string, (do not want to hard coded words, needs run time),

Please do needful,

Reply
a-kow responded on 13 Jun 2018 10:28 PM
My Badges
Suggested Answer

You have to find index of first space (" ") - strFind(), and get substring from your string, starting from space index - subStr().

Reply
Gautam . responded on 13 Jun 2018 11:45 PM
My Badges

Hi Akbarpasha,

you can use something like this:-

strDel("qwerty",1,1)

output - werty

put required string instead of "qwerty".

Thanks

Gautam

Reply
Shah_ responded on 14 Jun 2018 8:10 AM
My Badges
Suggested Answer

   str st = 'A B C D';

   str s;

   container con;

   con = str2con(st, ' ');

   con = conDel(con, 1,1);

   s = strReplace(con2Str(con), ',', ' ');

   info(s);

Reply
Palle Agermark responded on 18 Jun 2018 1:35 AM
My Badges
Suggested Answer
static void RemoveFirstWord(Args _args)
{
    str testString = 'This is a test';
    str newString; 
    int firstSpace = strFind(testString, ' ', 1, strLen(testString));
    
    if (firstSpace)
    {
        newString = subStr(testString, firstSpace + 1, strLen(testString));
    }
    
    info (newString);
}
Reply
a-kow responded on 13 Jun 2018 10:28 PM
My Badges
Suggested Answer

You have to find index of first space (" ") - strFind(), and get substring from your string, starting from space index - subStr().

Reply
Shah_ responded on 14 Jun 2018 8:10 AM
My Badges
Suggested Answer

   str st = 'A B C D';

   str s;

   container con;

   con = str2con(st, ' ');

   con = conDel(con, 1,1);

   s = strReplace(con2Str(con), ',', ' ');

   info(s);

Reply
Palle Agermark responded on 18 Jun 2018 1:35 AM
My Badges
Suggested Answer
static void RemoveFirstWord(Args _args)
{
    str testString = 'This is a test';
    str newString; 
    int firstSpace = strFind(testString, ' ', 1, strLen(testString));
    
    if (firstSpace)
    {
        newString = subStr(testString, firstSpace + 1, strLen(testString));
    }
    
    info (newString);
}
Reply

SBX - Two Col Forum

SBX - Migrated JS