2008-09-18 4 views
5

<tag> 형태의 태그가 포함 된 문자열이 있습니다. 이러한 태그의 인스턴스를 프로그래밍 방식으로 특수 ASCII 문자로 바꾸는 쉬운 방법이 있습니까? 예 : "<tab>"과 같은 태그를 ASCII 등가 인 '/t'으로 바꿉니 까?C# 문자열 조작 검색 및 바꾸기

답변

13
string s = "...<tab>..."; 
s = s.Replace("<tab>", "\t"); 
1

정규식 패턴은 트릭을 수행해야합니다.

+1

유용한 자습서 또는 코드 snippits? –

+0

나는 까다로운 것에서 나를 인도하기 위해 Expresso http://ultrapico.com의 열렬한 팬이다. – ddc0660

2
using System.Text.RegularExpressions; 

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