private void button1_Click(object sender, RoutedEventArgs e) { var ip = this.txtIP.Text.Trim(); //judge the ip format. Regex r = new Regex(@"^(\d{1,3}\.){3}\d{1,3}$"); Match m = r.Match(ip); if (!m.Success) { MessageBox.Show("error"); return; } HostsDal hostsDal = new HostsDal(); IList <HostItem> hostItems = hostsDal.GetHosts(); foreach (var item in hostItems) { Regex RegItem = new Regex(@"test([\s\S]*?).englishtown.com", RegexOptions.Compiled); if (!item.IsComment) { //item.Name Match match = RegItem.Match(item.Name); if (match.Success) { item.IP = ip; } } } hostsDal.Save(hostItems.ToList()); }
private void button1_Click(object sender, RoutedEventArgs e) { var ip = this.txtIP.Text.Trim(); //judge the ip format. Regex r = new Regex(@"^(\d{1,3}\.){3}\d{1,3}$"); Match m = r.Match(ip); if (!m.Success) { MessageBox.Show("error"); return; } HostsDal hostsDal = new HostsDal(); IList<HostItem> hostItems = hostsDal.GetHosts(); foreach (var item in hostItems) { Regex RegItem = new Regex(@"test([\s\S]*?).englishtown.com", RegexOptions.Compiled); if (!item.IsComment) { //item.Name Match match = RegItem.Match(item.Name); if (match.Success) { item.IP = ip; } } } hostsDal.Save(hostItems.ToList()); }