Remove Letter Accents

Регистрация
16.05.2014
Сообщения
145
Благодарностей
23
Баллы
18
hi guys anyone got a solution in C that will remove letter accents like here :
http://textmechanic.com/Remove-Letter-Accents.html

example:
żźćóóąžý

I found the following code, added System.Globalization into GAC but errors appear:

Код:
Error in action "CS0103" "The name 'UnicodeCategory' does not exist in the current context". [Row: 6; Column: 74]
Error in action "CS0103" "The name 'CharUnicodeInfo' does not exist in the current context". [Row: 6; Column: 33]
As i dont have much idea about C# i am stuck.

Код:
var text = (project.Variables["string"].Value);
{
    if (string.IsNullOrWhiteSpace(text))
        return text;

    text = text.Normalize(NormalizationForm.FormD);
    var chars = text.Where(c => CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark).ToArray();
    return new string(chars).Normalize(NormalizationForm.FormC);
}
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
Hi.
As you are new to c# use more simpler method:

C#:
project.Variables["accents"].Value = project.Variables["accents"].Value.Replace("ż", "z");
project.Variables["accents"].Value = project.Variables["accents"].Value.Replace("ź", "z");
project.Variables["accents"].Value = project.Variables["accents"].Value.Replace("ć", "c");
project.Variables["accents"].Value = project.Variables["accents"].Value.Replace("ó", "o");
Just replace all wrong letters with correct letters.
Set in project variable accents your text with wrong letters and it will come out with correct letters in same variable.

Cheers
 
  • Спасибо
Реакции: mikakojonkowski
Регистрация
16.05.2014
Сообщения
145
Благодарностей
23
Баллы
18
Thank you but this is not solution i am looking for, this is something i have been using before, its good if you got few characters in one language, but for all accents its not a solution.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 812
Благодарностей
1 187
Баллы
113
Thank you but this is not solution i am looking for, this is something i have been using before, its good if you got few characters in one language, but for all accents its not a solution.
Well if you are not new in c# and want to use more advanced codes then all I can suggest is to start to read some books about c# :-) It will help you much.

C#:
string text = project.Variables["accents"].Value;
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder();

foreach (var c in normalizedString)
{
    var unicodeCategory = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c);
    if (unicodeCategory != System.Globalization.UnicodeCategory.NonSpacingMark)
    {
        stringBuilder.Append(c);
    }
}

return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
Cheers
 
  • Спасибо
Реакции: Alouka и mikakojonkowski
Регистрация
16.05.2014
Сообщения
145
Благодарностей
23
Баллы
18
Working very well, thank you :ba:

Edit:

Guys keep in mind some characters are not replaced by this code, for example:


Код:
ÂÃÄÀÁÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿą, ć, ę, ł, ń, ó, ś, ź, ż.
returns;
Код:
AAAAAAÆCEEEEIIIIÐNOOOOOØUUUUYÞßaaaaaaæceeeeiiiiðnoooooøuuuuyþya, c, e, ł, n, o, s, z, z.
 
Последнее редактирование:

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)