Removing diacritics in Silverlight (String.Normalize issue)

后端 未结 2 1056
遥遥无期
遥遥无期 2020-12-11 06:21

I did create a function that transforms diacritic characters into non-diacritic characters (based on this post)

Here’s the code:

Public Function Remo         


        
2条回答
  •  Happy的楠姐
    2020-12-11 06:56

    Thanks for your answer Jim but I tried to implement the normalization class like the Mono Project did and at one point, I realized it was an overkill because there's way too many dependencies involved for something that should be simple.

    I came up with this simple implementation... it's not perfect, I know (This won't work for every language) but it will do the job for me until MS release a version of Silverlight with string normalization support.

     _    
    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
    
     _
    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
    

提交回复
热议问题