Replace accented letters

  • Thread starter Thread starter Luigi Z
  • Start date Start date
L

Luigi Z

Hi all,
having an huge string, with accented letters, how can I replace every
accented letter with the corrispondent upper case letter plus aphostrophe?

For example:

à -> A'

I'm using C# 2.0.

Thanks in advance.
 
à -> ascii value is 224,
À -> ascii value is 192,

Likewise, it will go in a sequence (check the Windows Character Map)

so to convert any lower case accented to Upper, just decrease its ASCII
value by 32
similarly to Upper to lower, you can sum its value by 32.
 
Kiruthik Nandha Kumar said:
à -> ascii value is 224,
À -> ascii value is 192,

Likewise, it will go in a sequence (check the Windows Character Map)

so to convert any lower case accented to Upper, just decrease its ASCII
value by 32
similarly to Upper to lower, you can sum its value by 32.

Ok, thanks Kiruthik.

Luigi
 
Luigi Z said:
having an huge string, with accented letters, how can I replace every
accented letter with the corrispondent upper case letter plus aphostrophe?

For example:

à -> A'

I'm using C# 2.0.

You could use a "brute force" approach:

string myString = "Jamón!!!";
StringBuilder sb = new StringBuilder();
foreach (char c in myString)
{
switch (c)
{
case 'á': sb.Append("A'"); break;
case 'é': sb.Append("E'"); break;
case 'í': sb.Append("I'"); break;
case 'ó': sb.Append("O'"); break;
case 'ú': sb.Append("U'"); break;
default: sb.Append(c);
}
}
return sb.ToString();
 
Luigi Z skrev:
Hi all,
having an huge string, with accented letters, how can I replace every
accented letter with the corrispondent upper case letter plus aphostrophe?

For example:

à -> A'

I'm using C# 2.0.

Thanks in advance.
A combination of String.Normalize and ToUpper() ?
 
Back
Top