Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace accented letters

0 views
Skip to first unread message

Luigi Z

unread,
Jan 8, 2009, 7:11:00 AM1/8/09
to
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.

--
Luigi

Kiruthik Nandha Kumar

unread,
Jan 8, 2009, 7:27:01 AM1/8/09
to
à -> 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.

Luigi Z

unread,
Jan 8, 2009, 8:56:01 AM1/8/09
to
"Kiruthik Nandha Kumar" wrote:

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

Alberto Poblacion

unread,
Jan 8, 2009, 9:04:33 AM1/8/09
to
"Luigi Z" <ciupazNoS...@inwind.it> wrote in message
news:D3AC4EE1-9AB8-4AD9...@microsoft.com...

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


Bjørn Brox

unread,
Jan 8, 2009, 4:45:51 PM1/8/09
to
Luigi Z skrev:
A combination of String.Normalize and ToUpper() ?

--
Bjørn Brox

0 new messages