How do I remove diacritics from a string in dynamics ax

你。 提交于 2019-12-11 16:28:04

问题


I'm trying to convert some strings, I'd like to be able to remove diacritics from strinf. (Exemple : éùèà would become euea) i have try this :

   static str AALRemoveDiacritics( System.String input )
    {
        int i;
    System.Text.NormalizationForm    FormD;
    str normalizedString = input.Normalize(FormD);
    System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

    for (i = 0; i < strLen(normalizedString); i++)
        {
        System.Char c = normalizedString[i];
        if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
            {
            stringBuilder.Append(c);
            }
        }

    return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
    }

thank you


回答1:


It looks like you tried making this post work in X++ and were very close.

Here's a working job I just wrote you can use:

static void AlexRemoveDiacritics(Args _args)
{
    str strInput = 'ÁÂÃÄÅÇÈÉàáâãäåèéêëìíîïòóôõ£ALEX';
    System.String input = strInput;
    str retVal;
    int i;

    System.Char c;
    System.Text.NormalizationForm FormD = System.Text.NormalizationForm::FormD;
    str normalizedString = input.Normalize(FormD);
    System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

    for (i = 0; i <= strLen(normalizedString); i++)
    {
        c = System.Char::Parse(subStr(normalizedString, i, 1));

        if (System.Globalization.CharUnicodeInfo::GetUnicodeCategory(c) != System.Globalization.UnicodeCategory::NonSpacingMark)
        {
            stringBuilder.Append(c);
        }
    }

    input = stringBuilder.ToString();
    input = input.Normalize();
    retVal = input;

    info(strFmt("Before: '%1'", strInput));
    info(strFmt("After: '%1'", retVal));
}


来源:https://stackoverflow.com/questions/25720863/how-do-i-remove-diacritics-from-a-string-in-dynamics-ax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!