Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function RemoveDiacritics(ByVal searchInString As String) As String
- Dim returnValue As String = ""
- Dim formD As String = searchInString.Normalize(System.Text.NormalizationForm.FormD)
- Dim unicodeCategory As System.Globalization.UnicodeCategory = Nothing
- Dim stringBuilder As New System.Text.StringBuilder()
- For formScan As Integer = 0 To formD.Length - 1
- unicodeCategory = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(formD(formScan))
- If unicodeCategory <> System.Globalization.UnicodeCategory.NonSpacingMark Then
- stringBuilder.Append(formD(formScan))
- End If
- Next
- returnValue = stringBuilder.ToString().Normalize(System.Text.NormalizationForm.FormC)
- Return returnValue
- End Function
- public string Normalize ()
- {
- return Normalization.Normalize (this, 0);
- }
- public string Normalize (NormalizationForm normalizationForm)
- {
- switch (normalizationForm)
- {
- default:
- return Normalization.Normalize (this, 0);
- case NormalizationForm.FormD:
- return Normalization.Normalize (this, 1);
- case NormalizationForm.FormKC:
- return Normalization.Normalize (this, 2);
- case NormalizationForm.FormKD:
- return Normalization.Normalize (this, 3);
- }
- }
- <System.Runtime.CompilerServices.Extension()> _
- Public Function RemoveDiacritics(ByVal searchInString As String) As String
- Dim returnValue As String = ""
- returnValue = searchInString
- returnValue = returnValue.ReplaceLowerAndUpperCase("À", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Á", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Â", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ã", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ä", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Å", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Æ", "A")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ç", "C")
- returnValue = returnValue.ReplaceLowerAndUpperCase("È", "E")
- returnValue = returnValue.ReplaceLowerAndUpperCase("É", "E")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ê", "E")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ë", "E")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ì", "I")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Í", "I")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Î", "I")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ï", "I")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ñ", "N")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ò", "O")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ó", "O")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ô", "O")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Õ", "O")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ö", "O")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ù", "U")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ú", "U")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Û", "U")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ü", "U")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Ý", "Y")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Æ", "AE")
- returnValue = returnValue.ReplaceLowerAndUpperCase("Œ", "OE")
- Return returnValue
- End Function
- <System.Runtime.CompilerServices.Extension()> _
- Public Function ReplaceLowerAndUpperCase(ByVal searchInString As String, ByVal oldString As String, ByVal newString As String) As String
- Dim returnValue As String = ""
- returnValue = searchInString.Replace(oldString.ToLower, newString.ToLower)
- returnValue = returnValue.Replace(oldString.ToUpper, newString.ToUpper)
- Return returnValue
- End Function
Advertisement
Add Comment
Please, Sign In to add comment