我是靠谱客的博主 怡然小笼包,这篇文章主要介绍C# 实现特殊字符快速转码,现在分享给大家,希望可以做个参考。

我就废话不多说了,大家还是直接看代码吧~

encodeURIComponent('n')
 "%0A"
 encodeURIComponent('\')
 "%5C"
 encodeURIComponent('/')
 "%2F" 
         encodeURIComponent(',')         "%2C"
          encodeURIComponent(''')
          %27
        encodeURIComponent(""")        "%22"
data = json;
 data = data.Replace("\", "%5C").Replace("n", "%0A");//.Replace("/","%2F");
.Replace(",", "%2C").Replace("'", "%27").Replace("\", "%5C").Replace("n", "%0A")
 
        encodeURIComponent(""")
        "%22"
       encodeURIComponent('\')
 "%5C"

补充:C#中Xml特殊字符的处理

以下是几个特殊字符的对应实体。

<

<

小于号

&gt;

>

大于号

&amp;

&

&apos;

'

单引号

&quot;

"

双引号

在C#中,直接调用C#提供的方法,保存之后就会自动将特殊字符转为对应实体:

string s =System.Security.SecurityElement.Escape(s);

以上为个人经验,希望能给大家一个参考,也希望大家多多支持靠谱客。如有错误或未考虑完全的地方,望不吝赐教。

最后

以上就是怡然小笼包最近收集整理的关于C# 实现特殊字符快速转码的全部内容,更多相关C#内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(183)

评论列表共有 0 条评论

立即
投稿
返回
顶部