[英]RegEx to remove Hexdecimal charecters from string in C#
There are some hexadecimal values hidden in some of my DB values that are causing me some trouble, does anyone have a RegEx to clean these out? 我的某些DB值中隐藏了一些十六进制值,这给我带来了麻烦,有人用RegEx清除它们吗?
Here is the error i am getting: 这是我得到的错误:
'', hexadecimal value 0x19, is an invalid character.
This post explains my problem completely but I am looking for a RegEx solution: http://seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/ 这篇文章完全解释了我的问题,但我正在寻找RegEx解决方案: http : //seattlesoftware.wordpress.com/2008/09/11/hexadecimal-value-0-is-an-invalid-character/
Instead of building XML strings by concatenation, you should use the XML handling classes provided with .NET. 不应通过串联构建XML字符串,而应使用.NET随附的XML处理类。 These will properly encode dangerous characters as XML entities and produce well-formed XML. 这些将正确地将危险字符编码为XML实体,并生成格式正确的XML。
Also, regular expressions don't do well for XML processing. 同样,正则表达式在XML处理中效果不佳。
I could, but it would also any occurence of dead, beef, bee, be, b, the dea in dear, any decimal digit, any a, b, c, d, e 我可以,但是也会发生任何死人,牛肉,蜜蜂,be,b,亲爱的dea,任何十进制数字,任何a,b,c,d,e
... ...
I oul, ut it woul lso ny ourn o , , , , , th in r, ny iml gt, ny , , , ,
... ...
See? 看到?
Do you need something like.... 您需要...吗?
Regex regex = new Regex("0x\\d\\d");
String Input = "this0x34is my 0x45 test 0x11";
string Result = regex.Replace(Input, " ");
I know you're hoping for Regex, but have you tried System.Security.SecurityElement.Escape
? 我知道您希望使用Regex,但是您是否尝试过System.Security.SecurityElement.Escape
? I believe this method is specifically intended for your use case. 我相信此方法专门用于您的用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.