views:

4413

answers:

4

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'?

+1  A: 

Regex patterns should do the trick.

ddc0660
Any useful tutorials or code snippits?
TK
I'm a big fan of Expresso http://ultrapico.com to guide me through the tough ones.
ddc0660
+10  A: 
string s = "...<tab>...";
s = s.Replace("<tab>", "\t");
Ferruccio
+2  A: 
using System.Text.RegularExpressions;

Regex.Replace(s, "TAB", "\t");//s is your string and TAB is a tab.
Burkhard
+2  A: 
public static Regex regex = new Regex("< tab >", RegexOptions.CultureInvariant | RegexOptions.Compiled);
public static string regexReplace = "\t";
string result = regex.Replace(InputText,regexReplace);
ddc0660