我需要在C#中使用此代码。请尽快 [英] I need this code in C# . plz ASAP
本文介绍了我需要在C#中使用此代码。请尽快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
If ifBlank(XMLStr, "") = "" Then Return "" : Exit Function
XMLStr = XMLStr.Replace("&", "&")
XMLStr = XMLStr.Replace("<", "<")
XMLStr = XMLStr.Replace(">", ">")
Dim str As Char = <string>"</string>
XMLStr = XMLStr.Replace(str, """)
XMLStr = XMLStr.Replace("'", "'")
Return XMLStr
修复HTML编码,假设从常规变为编码。 [/ EDIT]
fixed HTML encoding, assuming going from "regular" to "encoded". [/EDIT]
推荐答案
究竟是什么代码应该做什么?
你所拥有的是对String的一系列调用。用相同的两个参数替换:所以它们将用相同的子串替换子串,并且在实践中什么都不做。
例如,如果我有字符串
What is that code supposed to do, exactly?
All you have is a sequence of calls to String.Replace with the two parameters the same: so they will replace a substring with the same substring, and do nothing at all in practice.
For example, if I have the string
hello&there
我这样做:
and I do this:
XMLStr = "hello&there"
XMLStr = XMLStr.Replace("&", "&")
然后我最终得到
Then I end up with
hello&there
并且替换的调用已经完成一无所获。
那么你想做什么?因为如果您尝试使用HTML enocding来替换网页中的可打印标记,那么最好使用Server.HTMLEncode来完成这项任务...
And the call to replace has done a total on nothing.
So what are you trying to do? Because if you are trying to do HTML enocding to replace tag with printable ones in a web page, then you would be better off using Server.HTMLEncode which will do the job for you...
如果我理解你的困境,你需要这个代码:
Dim str As Char =< string>
XMLStr = XMLStr。替换(str,)
等价于C#,即:
XMLStr = XMLStr .Replace(\,);
HTMLEncode是解决更大问题的正确方法。
If I understand your dilemna, you want this code:
Dim str As Char = <string>"
XMLStr = XMLStr.Replace(str, """)
in equivalent C#, which is:
XMLStr = XMLStr.Replace("\"", """);
HTMLEncode is the proper solution to the larger problem.
这篇关于我需要在C#中使用此代码。请尽快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文