AX / D365FO – Remove a string in another string with X++

To remove a substring from another string you can use this custom method

public static str strDelete(str _stringSearch, str _strDelete)
{
        //Get initial position of the string to find
        int position = strScan(_stringSearch, _strDelete,1,strLen(_stringSearch));

        //Delete string to find from original string
        if(position != 0)
        {
            _stringSearch = strDel(_stringSearch, position, strLen(_strDelete));
        }
    
    return _stringSearch;
}

Leave a comment