C#更换逃脱越狱 [英] C# Replacing escaped escapes

查看:153
本文介绍了C#更换逃脱越狱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伊夫解析的文本文件转换成列表<串> 对象和测试文件中包含 \\ n \\ t ,但是一旦我的输出字符串到控制台它们显示为\\ n和\\ t的,而不是一个新的生产线和一个标签。

Ive parsed a text file into a List<string> object and the test file contains \n and \t, however once I output the strings to console they appear as "\n" and "\t" rather than a new line and a tab.

目前我使用 myList上[I] .Replace(@\\ n,\\ n)。更换(@\\ t的\\ t的)但这似乎有点麻烦,特别是更多的转义序列需要在未来以复加。

At the moment i'm using myList[i].Replace(@"\n", "\n").Replace(@"\t", "\t") but this seems a little cumbersome, especially if more escape sequences need to be added in the future.

时他们没有办法未逃脱逃脱序列?像 string.UnEscape 的东西将只是完美。

Is their any way to un-escape the escaped sequences? Something like string.UnEscape would be just to perfect.

推荐答案

我不知道这是否会后做的正是你在做什么,但有一个的 UNESCAPE 的方法正则表达式命名空间。

I'm not sure if this will do exactly what you're after but there is an Unescape method in the RegEx namespace.

string result = Regex.Unescape(myList[i]);

这篇关于C#更换逃脱越狱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆