Regex ile dosya okumak

17 Haziran 2014 Salı

bir txt satırının içindeki şeyleri sırayla okumak istediğimiz zaman lazım olabilir.


string i = he.DosyaOku(Server.MapPath("~/common/2014.xml"));
            List<string> link = new List<string>();

            string word = i;
            Regex rx = new Regex("<loc>(.*?)</loc>", RegexOptions.IgnoreCase);
            foreach (Match m in rx.Matches(word))
            {
                string lm = m.Value;
                link.Add(m.Value.Replace("<loc>", "").Replace("</loc>", ""));
                //m.Value="aziertyz" olur
                //m.Index=6 olur
                //m.Length=8 olur
            }
            foreach (var item in link)
            {
                Response.Write(item + "<br>");
                da.ExecuteNonQuery("insert Link values(@u)",item);
            }


Continue Reading...