0

我正在尝试转换一些字符串,我希望能够从 strinf 中删除变音符号。(例如:éùèà 会变成 euea)我试过这个:

   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);
    }

谢谢你

4

1 回答 1

2

看起来您尝试让这篇文章在 X++ 中工作并且非常接近。

这是我刚刚写的一份工作,你可以使用:

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));
}
于 2014-09-08T18:15:25.377 回答