Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regualr expression

Status
Not open for further replies.

sand133

Programmer
Jun 26, 2004
103
GB
got this "Intesa Sanpaolo ST: the downside prevails <ISP.MI>"

i want to extract all data in <...>.

how woudl i do it in c#

thanks
 
You can try the following:

Code:
String s = "Intesa Sanpaolo ST: the downside prevails <ISP.MI>";
String result = s.SubString( s.IndexOf( '<' ), s.IndexOf( '>' ) - s.IndexOf( '<' ) );

You may have to add a +1 or -1 to avoid the '<' or '>' characters in the result.

The Substring method takes the start index and length as parameters.

There are several other ways to do that I'm sure, this is just the first thing that I thought of.

|| ABC
 
RegEx i've done as below to extract just the <title> tag out of a web page header, maybe you can adjust it to your requirements?

Code:
    public string GetWebPageTitle(string url)
    {
        string regex = "(?<=title=\")(.*?)(\")";
        string title = string.Empty;

        FileStream fs = new FileStream(Server.MapPath(url), FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs, Encoding.UTF8);

        //get just the first two lines
        title = sr.ReadLine();
        title += sr.ReadLine();

        Regex ex = new Regex(regex, RegexOptions.IgnoreCase);
        title = ex.Match(title).Value.Replace("\"", "").Trim();

        sr.Close();
        fs.Close();

        return title;
    }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top