我需要在C#中使用此代码。请尽快

编程入门 行业动态 更新时间:2024-10-22 23:11:00
本文介绍了我需要在C#中使用此代码。请尽快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

If ifBlank(XMLStr, "") = "" Then Return "" : Exit Function XMLStr = XMLStr.Replace("&", "&amp;") XMLStr = XMLStr.Replace("<", "&lt;") XMLStr = XMLStr.Replace(">", "&gt;") Dim str As Char = <string>"</string> XMLStr = XMLStr.Replace(str, "&quot;") XMLStr = XMLStr.Replace("'", "&apos;") 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#中使用此代码。请尽快

本文发布于:2023-11-07 22:48:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:请尽快   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!