Replace accented letters

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.
 
K

Kiruthik Nandha Kumar

à -> 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.
 
L

Luigi Z

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
 
A

Alberto Poblacion

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();
 
B

Bjørn Brox

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() ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top