问题
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