這個問題類似於How to emulate MySQLs utf8_general_ci collation in PHP string comparisons但我想要的功能是vb.net而不是PhP。在vb.net中是否有函數可以告訴我們在UTF8 unicode整理下2字符串是否相同?
最近我做了很多據稱獨特的關鍵。
某些密鑰在UTF8 unicode整理下是等效的。
例如,看看這2項:
拜爾斯-街道bistro__38.15_-79.07 拜爾斯-街頭小酒館__38.15_-79.07
如果我粘貼到頭版,並查看源代碼,你會看到
拜爾斯-街道bistro__38.15_-79.07
拜爾斯-街頭小酒館 __38.15_-79.07
注意:在堆棧溢出中,它們看起來仍然不同。
我知道這是不一樣的。我猜即使在堆棧交換中它也沒有顯示。假設我有100萬條這樣的記錄,並且我想測試2個字符串是否會被MySQL UTF8歸類聲明爲相同。我想在上傳之前知道。我怎麼做。
所以vb.net認爲那些是不同的鍵。當我們創建mysql查詢並將其上傳到數據庫時,數據庫抱怨它是相同的密鑰。只有一個抱怨,100萬個數據庫的上傳將被卡住。我們甚至不知道該死的是什麼?無論如何,我們可以在哪裏查看?
無論如何,我想要一個函數,當給出2個字符串將告訴我他們是否會計數爲相同或不。
如果可能,我們需要一個將字符串轉換爲最「標準」形式的函數。
例如,似乎什麼都不編碼,函數會將所有這些沒有字符並消除它。
有沒有這樣的事情?
到目前爲止,這是我所做的。我需要更全面的東西。
Private Function StraightenQuotesReplacement() As Generic.Dictionary(Of String, String)
Static replacement As Generic.Dictionary(Of String, String)
If replacement Is Nothing Then
replacement = New Generic.Dictionary(Of String, String)
replacement.Add(ChrW(&H201C), """")
replacement.Add(ChrW(&H201D), """")
replacement.Add(ChrW(&H2018), "'")
replacement.Add(ChrW(&H2019), "'")
End If
Return replacement
End Function
<Extension()>
Public Function straightenQuotes(ByVal somestring As String) As String
For Each key In StraightenQuotesReplacement.Keys
somestring = somestring.Replace(key, StraightenQuotesReplacement.Item(key))
Next
Return somestring
End Function
<Extension()>
Public Function germanCharacter(ByVal s As String) As String
Dim t = s
t = t.Replace("ä", "ae")
t = t.Replace("ö", "oe")
t = t.Replace("ü", "ue")
t = t.Replace("Ä", "Ae")
t = t.Replace("Ö", "Oe")
t = t.Replace("Ü", "Ue")
t = t.Replace("ß", "ss")
Return t
End Function
<Extension()>
Public Function japaneseCharacter(ByVal s As String) As String
Dim t = s
t = t.Replace("ヶ", "ケ")
Return t
End Function
<Extension()>
Public Function greekCharacter(ByVal s As String) As String
Dim t = s
t = t.Replace("ς", "σ")
t = t.Replace("ι", "ί")
Return t
End Function
<Extension()>
Public Function franceCharacter(ByVal s As String) As String
Dim t = s
t = t.Replace("œ", "oe")
Return t
End Function
<Extension()>
Public Function RemoveDiacritics(ByVal s As String) As String
Dim normalizedString As String
Dim stringBuilder As New StringBuilder
normalizedString = s.Normalize(NormalizationForm.FormD)
Dim i As Integer
Dim c As Char
For i = 0 To normalizedString.Length - 1
c = normalizedString(i)
If CharUnicodeInfo.GetUnicodeCategory(c) <> UnicodeCategory.NonSpacingMark Then
stringBuilder.Append(c)
End If
Next
Return stringBuilder.ToString()
End Function
<Extension()>
Public Function badcharacters(ByVal s As String) As String
Dim t = s
t = t.Replace(ChrW(8206), "")
Return t
End Function
<Extension()>
Public Function sanitizeUTF8_Unicode(ByVal str As String) As String
Return str.ToLower.removeDoubleSpaces.SpacetoDash.EncodeUrlLimited.straightenQuotes.RemoveDiacritics.greekCharacter.germanCharacter
End Function
我需要能夠以編程方式執行此操作。如果沒有人際間的緊張情緒顯示「ä」與「ae」相同 –
如果您在System.Text.NormalizationForm上搜索Visual Studio幫助,我想您可能會找到答案。讓我們知道你發現了什麼! – SSS
這會做。我想我需要更多。 –