我正在嘗試運行以下代碼行,用我們的資料庫可以存盤的引號替換 Microsoft Word 引號。我需要解決用戶將字串從 Microsoft Word 復制到我的文本區域的問題。
instrText = instrText.Replace(""", """).Replace(""", """)
我收到引數數量的語法錯誤。

我嘗試過字符轉義和其他幾種格式化引數的方法,但沒有運氣。
uj5u.com熱心網友回復:
這改變了單詞中的“智能”引號,
'non standard quotes
Dim Squotes() As Char = {ChrW(8216), ChrW(8217)} 'single
Dim Dquotes() As Char = {ChrW(8220), ChrW(8221)} 'double
'build test string
Dim s As String = ""
For x As Integer = 0 To Squotes.Length - 1
s &= x.ToString & Squotes(x) & ", "
Next
For x As Integer = 0 To Dquotes.Length - 1
s &= (x Squotes.Length).ToString & Dquotes(x) & ", "
Next
'replace
For Each c As Char In Squotes
s = s.Replace(c, "'"c)
Next
For Each c As Char In Dquotes
s = s.Replace(c, ControlChars.Quote)
Next
uj5u.com熱心網友回復:
請嘗試以下操作:
Private Function CleanInput(input As String) As String
DisplayUnicode(input)
'8216 = &H2018 - left single-quote
'8217 = &H2019 - right single-quote
'8220 = &H201C - left double-quote
'8221 = &H201D - right double-quote
'Return input.Replace(ChrW(&H2018), Chr(39)).Replace(ChrW(&H2019), Chr(39)).Replace(ChrW(&H201C), Chr(34)).Replace(ChrW(&H201D), Chr(34))
Return input.Replace(ChrW(8216), Chr(39)).Replace(ChrW(8217), Chr(39)).Replace(ChrW(8220), Chr(34)).Replace(ChrW(8221), Chr(34))
End Function
Private Sub DisplayUnicode(input As String)
For i As Integer = 0 To input.Length - 1
Dim lngUnicode As Long = AscW(input(i))
If lngUnicode < 0 Then
lngUnicode = 65536 lngUnicode
End If
Debug.WriteLine(String.Format("char: {0} Unicode: {1}", input(i).ToString(), lngUnicode.ToString()))
Next
Debug.WriteLine("")
End Sub
用法:
Dim cleaned As String = CleanInput(TextBoxInput.Text)
資源:
- ASCII 表
- C#如何用直引號替換微軟的Smart Quotes?
- 如何在 VB.Net 字串文字中表示 Unicode 字符?
注意:也用于Character MapWindows。
uj5u.com熱心網友回復:
您有一個適用于上述的解決方案,但與您的原始形式保持一致:
instrText = instrText.Replace(ChrW(8220), """"c).Replace(ChrW(8221), """"c)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/384924.html
上一篇:即使員工ID正確,也無法讀取
