2010-07-01 136 views
-1

以外的不需要的文本我想從文本框中刪除除<>之外的所有文本。刪除<>

+0

請澄清什麼是你想做的事 - 刪除除該字符以外的所有文本< and >或刪除除< and >之間包含的任何文本之外的所有文本。 – 2010-07-01 01:37:20

+0

therir是這樣的電子郵件www.abc.com <[email protected]> ,我想刪除多餘的文字這個「www.abc.com」 – azeem 2010-07-01 01:50:00

回答

1

這是從我的頭頂,但希望將引導你在正確的方向:)

String email = "www.abc.com <[email protected]>"; 
String result = ""; 

int firstIndex = email.IndexOf('<'); 
int lastIndex = email.IndexOf('>'); 
if(lastIndex > firstIndex) 
    result = email.Substring(firstIndex + 1, lastIndex-firstIndex-1); 
+0

好yar好yar – azeem 2010-07-01 02:07:40

1

試試這個

var strText = "asdasd<data1>sdsdf <data2>sdfsfsdf"; 
var pattern = new Regex(@"\<(?<data>(.+?))\>"); 
var matches = pattern.Matches(strText); 
foreach (Match match in matches) 
{ 
    Console.WriteLine("Data: " + match.Groups["data"]); 
} 
//Output: 
//Data: data1 
//Data: data2 
相關問題