Remove accents from String .NET

Posted by developerit on Developer IT See other posts from Developer IT or by developerit
Published on Fri, 12 Mar 2010 23:09:52 +0000 Indexed on 2010/03/16 14:51 UTC
Read the original article Hit count: 8735

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


© Developer IT or respective owner

Related posts about Developer IT

Related posts about Posts