所以我有一個ASP.Net(vb.net)應用程序。它有一個文本框,用戶正在將來自Microsoft Word的文本粘貼到其中。因此,諸如long dash(charcode 150)之類的東西即將通過輸入。其他例子是聰明的引號或重音字符。在我的應用程序中,我將它們編碼爲xml,並將其作爲XML存儲過程的xml參數傳遞給數據庫。它被插入到數據庫中,就像用戶輸入它一樣。字符支持問題 - 如何將較高的ASCII字符轉換爲較低的ASCII字符
問題是讀取此數據的應用程序不喜歡這些字符。所以我需要將它們翻譯成較低的ascii(我認爲是7bit)字符集。我怎麼做?我如何確定它們在哪些編碼中,以便我可以執行以下操作。並且只是要求ASCII等價物能夠智能地翻譯它們,還是必須爲此編寫一些代碼?
也可能在網頁中解決這個問題可能更容易一開始。當您從Word中複製字符選擇時,會在剪貼板中放入多種格式。直接的文字是我想要的。有沒有辦法讓HTML文本框在用戶粘貼到文本時獲取該文本?我必須以某種方式設置網頁的編碼嗎?
System.Text.Encoding.ASCII.GetString(System.Text.Encoding.GetEncoding(1251).GetBytes(text))
與輸入編碼成XML應用程序代碼:
Protected Function RequestStringItem(_
ByVal strName As System.String) As System.String
Dim strValue As System.String
strValue = Me.Request.Item(strName)
If Not (strValue Is Nothing) Then
RequestStringItem = strValue.Trim()
Else
RequestStringItem = ""
End If
End Function
' I get the input from the textboxes into an array like this
m_arrInsertDesc(intIndex) = RequestStringItem("txtInsertDesc" & strValue)
m_arrInsertFolder(intIndex) = RequestInt32Item("cboInsertFolder" & strValue)
' create xml file for inserts
strmInsertList = New System.IO.MemoryStream()
wrtInsertList = New System.Xml.XmlTextWriter(strmInsertList, System.Text.Encoding.Unicode)
' start document and add root element
wrtInsertList.WriteStartDocument()
wrtInsertList.WriteStartElement("Root")
' cycle through inserts
For intIndex = 0 To m_intInsertCount - 1
' if there is an insert description
If m_arrInsertDesc(intIndex).Length > 0 Then
' if the insert description is of the appropriate length
If m_arrInsertDesc(intIndex).Length <= 96 Then
' add element to xml
wrtInsertList.WriteStartElement("Insert")
wrtInsertList.WriteAttributeString("insertdesc", m_arrInsertDesc(intIndex))
wrtInsertList.WriteAttributeString("insertfolder", m_arrInsertFolder(intIndex).ToString())
wrtInsertList.WriteEndElement()
' if insert description is too long
Else
m_strError = "ERROR: INSERT DESCRIPTION TOO LONG"
Exit Function
End If
End If
Next
' close root element and document
wrtInsertList.WriteEndElement()
wrtInsertList.WriteEndDocument()
wrtInsertList.Close()
' when I add the xml as a parameter to the stored procedure I do this
cmdAddRequest.Parameters.Add("@insert_list", OdbcType.NText).Value = System.Text.Encoding.Unicode.GetString(strmInsertList.ToArray())
這就是我輸入的內容。 這是一些 - 帶有「有趣」字符的文字,例如: 這就是我想要的輸出。 這是一些 - 帶有「有趣」字符的文字,例如:áíóññѺª¿?ÇüéâääååçêëèïîìÄÅÉæÆòòûùÿûÜÜ£¥?ƒá – 2009-08-07 16:08:26