C# 实现特殊字符快速转码
- 作者: 嗫?暁雲?
- 来源: 51数据库
- 2021-07-08
我就废话不多说了,大家还是直接看代码吧~
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特殊字符的处理
以下是几个特殊字符的对应实体。
|
< |
< |
小于号 |
|
> |
> |
大于号 |
|
& |
& |
和 |
|
' |
' |
单引号 |
|
" |
" |
双引号 |
在c#中,直接调用c#提供的方法,保存之后就会自动将特殊字符转为对应实体:
string s =system.security.securityelement.escape(s);
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
推荐阅读
