I want to remove all text except the text within <>
's from a textbox.
Asked
Active
Viewed 226 times
-1
-
Please clarify what it is you want to do - remove all text except for that characters < and > or remove all text except for any text contained between a < and >. – Michael Shimmins Jul 01 '10 at 01:37
-
therir is emails like this www.abc.com
and i want to remove extra text this "www.abc.com" – azeem Jul 01 '10 at 01:50
2 Answers
1
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);

Jacob
- 1,242
- 2
- 9
- 14
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

Nitin Chaudhari
- 1,497
- 16
- 39