I wrote two functions in .NET to remove easly any accent and umlaut marks from a string and to get the equivalent non-accented string, this is very useful to normalize URLs; for example, with the StripAccentMarks() method, from “àbcdèéfghìlmnòpqrstùvzäöüÄÖÜ” u’ll get “abcdeefghilmnopqrstuvzaouAOU”;
besides, if u’ll need to convert each german umlaut to the corresponding two-letter chars, u can also use the ReplaceGermanUmlauts() method…
[sourcecode language=”vb”] Public Shared Function StripAccentMarks(ByVal input_string As String) As StringDim n_s As String = input_string.Normalize(NormalizationForm.FormD)
Dim s As New StringBuilder()
Dim c As Char
For i As Integer = 0 To n_s.Length – 1
c = n_s(i)
If System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c) <> System.Globalization.UnicodeCategory.NonSpacingMark Then
s.Append(c)
End If
Next
Return s.ToString
End Function
[/sourcecode] [sourcecode language=”vb”] Public Shared Function ReplaceGermanUmlauts(ByVal input_string As String) As String
Dim s As String = input_string</pre>
s = s.Replace("ä", "ae")
s = s.Replace("ö", "oe")
s = s.Replace("ü", "ue")
s = s.Replace("Ä", "Ae")
s = s.Replace("Ö", "Oe")
s = s.Replace("Ü", "Ue")
s = s.Replace("ß", "ss")
Return s
End Function
[/sourcecode]
Have a nice day!
Max 😀
Leave a Reply