IMG-LOGO

How to convert accented characters in ASP.Net C#?

andy - 27 Jul, 2013 12812 Views 1 Comment

They can be considered as special characters that contains specific symbols or accents attached to them. For ex: ÁÇËÌÖ

To convert those special characters in C#, you can use the following function.

//this function  will accept codepage in integer and accented characters in string
public string ConvertAccentedString(int codepage, string accentedString) {
    return System.Text.Encoding.ASCII.GetString( System.Text.Encoding.GetEncoding( codepage ).GetBytes( accentedString ));
}

The codepage represents the unicode of specific language. See below example list of codepage:

codepage unicode

How to use the function?

Please see the following example:

protected void Page_Load(object sender, EventArgs e) {
    string accentedString = "ÁÇËÌÖ";
    Response.Write("After conversion to string: " + ConvertAccentedString(1251, accentedString));  
}

The above demo will print the following result: ACEIO

Comments

Sebastien DErrico
18 Mar, 2016
Thank you! Very useful!
Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.

Related Articles

How to remove html tags from string in c#?

Sometimes you need to remove HTML tags from string to ensure there are no dangerous or malicious scripts especially when you want to store the string or data text into the database.