这段程序是把空格 和回车转换保存到xml文件的方法Public Function encodingtext(ByVal text As String) As String '将输入的回车符转换为“<br>” Dim l As Integer l = Len(text) Dim i As Integer Dim str As String = text Dim isHTMLTag As Boolean = False While i <> l - 1 Dim s As String = str.Substring(i, 1) Dim ascOfchar As Integer = Asc(str.Substring(i, 1)) If (ascOfchar = Asc("<")) Then isHTMLTag = True If (ascOfchar = Asc(">")) Then isHTMLTag = False If (Not isHTMLTag) Then If Asc(str.Substring(i, 1)) = 13 Then If Asc(str.Substring(i + 1, 1)) = 10 Then str = str.Remove(i, 2) str = str.Insert(i, "<br>") l = l + 2 End If End If If Asc(str.Substring(i, 1)) = 32 Then str = str.Remove(i, 1) str = str.Insert(i, " ") l = l + 11 End If End If i = i + 1 End While Return str End Function
我昨天用进行格式转换后在换行处加入了<br/>及空白处加入空白符但是浏览器报错不能解析
是从TextBox控件读出,就是在换行处加入<br/>
我是格式化后在插入到XML文件的,可是浏览器不能解析
<root>
<![CDATA[
这里可以放任何你想要的字符: <br> < <<<&
]]>
</root>
Dim l As Integer
l = Len(text)
Dim i As Integer
Dim str As String = text
Dim isHTMLTag As Boolean = False
While i <> l - 1
Dim s As String = str.Substring(i, 1)
Dim ascOfchar As Integer = Asc(str.Substring(i, 1))
If (ascOfchar = Asc("<")) Then isHTMLTag = True
If (ascOfchar = Asc(">")) Then isHTMLTag = False
If (Not isHTMLTag) Then
If Asc(str.Substring(i, 1)) = 13 Then
If Asc(str.Substring(i + 1, 1)) = 10 Then
str = str.Remove(i, 2)
str = str.Insert(i, "<br>")
l = l + 2
End If
End If
If Asc(str.Substring(i, 1)) = 32 Then
str = str.Remove(i, 1)
str = str.Insert(i, " ")
l = l + 11
End If
End If
i = i + 1
End While
Return str
End Function