2012-07-27 109 views

回答

1

使用正則表達式:

Regex g; 
Match m; 
g = new Regex("//(.*)\n"); // if you have just alphabet characters replace .* with \w* 
m = g.Match(input); 
if (m.Success == true) 
    output = m.Groups[1].Value; 
+0

我已經嘗試了上面的正則表達式//; \ n1; 2。和預期的產出是;它介於//和\ n之間。但匹配沒有找到。 – Naresh 2012-07-27 09:50:20

+0

感謝薄霧...它正在工作 – Naresh 2012-07-27 09:51:54

+0

再一次的事情 - 如果你確定輸入以//開始//你應該使用「^ //(。*)\ n」。請記住,RegEx將匹配輸入字符串「// one \ ntwo \ n」like「one \ ntwo」 – 2012-07-27 09:57:01

3

正則表達式很好,所有,但爲什麼不使用Substring?

string input = "//{characters}\n"; 
string result = input.Split('\n')[0].Substring(2); 

string result = input.Substring(2, input.Length - 3); 
+0

Yea..we can do string operations,but that是我最後的選擇。 – Naresh 2012-07-27 09:52:51

1

這應該工作:

string s1 = "//{characters}\n"; 
string final = (s1.Replace("//", "").Replace("\n", "")); 
相關問題