Удаление нежелательного текста снаружи <> - PullRequest
0 голосов
/ 01 июля 2010

Я хочу удалить весь текст, кроме текста в <> из текстового поля.

Ответы [ 2 ]

1 голос
/ 01 июля 2010

Попробуйте это

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
1 голос
/ 01 июля 2010

Это не в моей голове, но, надеюсь, направит вас в правильном направлении :) 1001

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);
...