开发者

Removing unwanted text outside <>

I want to remove a开发者_运维百科ll text except the text within <>'s from a textbox.


This is off the top of my head, but hopefully will steer you in the right direction :)

String email = "www.abc.com <abc@gmail.com>";
String result = "";

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


Try this

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜