【发布时间】:2012-03-23 02:07:09
【问题描述】:
嗯,我有这个小方法:
static string escapeString(string str) {
string s = str.Replace(@"\r", "\r").Replace(@"\n", "\n").Replace(@"\t", "\t");
Regex regex = new Regex(@"\\x(..)");
var matches = regex.Matches(s);
foreach (Match match in matches) {
s = s.Replace(match.Value, ((char)Convert.ToByte(match.Value.Replace(@"\x", ""), 16)).ToString());
}
return s;
}
它替换了我在 args[0] 中得到的字符串中的“\x65”。
但我的问题是:“\\x65”也将被替换,所以我得到“\e”。我试图找出一个正则表达式来检查是否有多个反斜杠,但我没有运气。
有人能给个提示吗?
【问题讨论】:
-
你在重塑Regex.Unescape吗?
-
为什么
\\x65不能变成\e? -
@bzlm: 因为第一个 \ 转义了第二个 \
-
见鬼!那很简单!多谢! :)
-
在问题中使用“gimme”这个词是非常不可取的。