如何替换 vb.net 中字符串中的“&”。我尝试过:
str2 As String = Replace(str, "&"c, "&")
str2 As String = Replace(str, "&", "&")
str2 As String = Replace(str, chr(38), "&")
由于某种原因,代码在这里不起作用。我在 URL 中使用参数并使用 request 来存储该参数。它绝对存储正确,因为当我调试时,我看到 strOne 正在获取正确的值。
Dim strOne As String = Request("One")
在此处调试,观看 strOne = "ABC D&E"
If Not strOne Is Nothing Then
strOne = strOne.Replace("&", "&")
Else
strOne = String.Empty
End If
然后它转到要替换的行,但没有。为什么??? 好吧,我明白了......
“&”与“&”不一样,所以我从 watch 上复制并粘贴它并修复了它。他们怎么不一样呢?不同的编码?
谢谢!
最佳答案
你可以这样做:
Dim str2 As String = str.Replace("&", "&")
但如果是因为网址,你应该看看 this post
you might look at System.Web.HttpServerUtility.HtmlEncode instead.
关于vb.net - VB.net 中的字符串替换 "&",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5671672/