所以我有一个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