Showing posts with label regex. Show all posts
Showing posts with label regex. Show all posts

Saturday, January 12, 2013

ตัวอย่าง match regex แล้ว assign ใส่ groups


ตัดมาจาก code ในส่วยที่เคยใช้ไป get ราคาหุ้น

    this.Html = HttpRequester.RequestHttp(string.Format(this.RequestUrl, tickerSymbol), out errorCode);
    if (errorCode < 0)
    {
        return errorCode;
    }
    string RegexPricePattern = @"<span class=""time_rtq_ticker""><span id=""[^>\t\r\n\v\f]*"">(?<price>\d*\.\d*)</span>?";
    Regex priceFinder = new Regex(RegexPricePattern, RegexOptions.IgnoreCase);
    Match priceMatch = priceFinder.Match(this.Html);
    if (priceMatch.Success)
    {
        string priceString = priceMatch.Groups["price"].Value;
    }