我想从文本框中删除除<>
内的文字以外的所有文字。
答案 0 :(得分:1)
这是我的头脑,但希望能引导你朝着正确的方向前进:)
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);
答案 1 :(得分: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