Some strings can consist of special diacritics (accents) like é, è, ü, ^,…  For several reasons (url rewriting for example) it can be necessary to remove those diacritics and just have the normal character as a result.  For example, Hélène should be Helene.  Instead of searching the string for those special characters and replacing them by their equivalent there is another solution available in .NET.  Underneath you can find the VB.NET function to remove the diacritics from a string you pass as a parameter.  You need to import 2 extra namespaces: System.Text.NormalizationForm, System.Globalization

Public Function RemoveDiacritics(ByVal pText As String) As String

Dim strNormalized As String = pText.Normalize(NormalizationForm.FormD)
Dim strBuilder As New StringBuilder()
Dim i As Integer

For i = 0 To strNormalized.Length - 1

Dim c As Char = strNormalized(i)
If (CharUnicodeInfo.GetUnicodeCategory(c) <> UnicodeCategory.NonSpacingMark) Then
strBuilder.Append(c)
End If
Next

Return strBuilder.ToString()

End Function

12/11/2009 - 16:43