Remove accents from String .NET

12 Mar

Private Const ACCENT As String = “ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÌÍÎÏìíîïÙÚÛÜùúûüÿÑñÇç”
Private Const SANSACCENT As String = “AAAAAAaaaaaaOOOOOOooooooEEEEeeeeIIIIiiiiUUUUuuuuyNnCc”
Public Shared Function FormatForUrl(ByVal uriBase As String) As String
If String.IsNullOrEmpty(uriBase) Then
Return uriBase
End If

‘// Declaration de variables

Dim chaine As String = uriBase.Trim.Replace(” “, “-“)

chaine = chaine.Replace(” “c, “-“c)

chaine = chaine.Replace(“–“, “-“)

chaine = chaine.Replace(“‘”c, String.Empty)

chaine = chaine.Replace(“?”c, String.Empty)

chaine = chaine.Replace(“#”c, String.Empty)

chaine = chaine.Replace(“:”c, String.Empty)

chaine = chaine.Replace(“;”c, String.Empty)

‘// Conversion des chaines en tableaux de caractŠres

Dim tableauSansAccent As Char() = SANSACCENT.ToCharArray

Dim tableauAccent As Char() = ACCENT.ToCharArray

‘// Pour chaque accent

For i As Integer = 0 To ACCENT.Length – 1

‘ // Remplacement de l’accent par son ‚quivalent sans accent dans la chaŒne de caractŠres

chaine = chaine.Replace(tableauAccent(i).ToString(), tableauSansAccent(i).ToString())

Next

‘// Retour du resultat

Return chaine

End Function


Published at http://www.developerit.com/2010/03/16/remove-accents-from-string-net from http://www.developerit.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: