I have a string which contain tags in the form < tag >
. Is there an easy way for me to programmatically replace instances of these tags with special ascii characters? e.g. replace a tag like "< tab >"
with the ascii equivelent of '/t'
?
我有一个字符串,其中包含
4 个解决方案
#1
13
string s = "...<tab>...";
s = s.Replace("<tab>", "\t");
#2
2
using System.Text.RegularExpressions;
Regex.Replace(s, "TAB", "\t");//s is your string and TAB is a tab.
#3
2
public static Regex regex = new Regex("< tab >", RegexOptions.CultureInvariant | RegexOptions.Compiled);
public static string regexReplace = "\t";
string result = regex.Replace(InputText,regexReplace);
#4
1
Regex patterns should do the trick.
正则表达式模式应该可以解决问题。
#1
13
string s = "...<tab>...";
s = s.Replace("<tab>", "\t");
#2
2
using System.Text.RegularExpressions;
Regex.Replace(s, "TAB", "\t");//s is your string and TAB is a tab.
#3
2
public static Regex regex = new Regex("< tab >", RegexOptions.CultureInvariant | RegexOptions.Compiled);
public static string regexReplace = "\t";
string result = regex.Replace(InputText,regexReplace);
#4
1
Regex patterns should do the trick.
正则表达式模式应该可以解决问题。