-IP: 19283.123.12.3
-Contact As: ****@mail.ru
-Admin: admin
-IP: 123.12.312.31
-Contact As: ****@mail.ru
-Admin: admin
-IP: 23.11.23.123
-Contact As: ****@mail.ru
-Admin: admin
IP: 19283.123.12.3
IP: 123.12.312.31
IP: 23.11.23.123
using System;
using System.Linq;
namespace parse_ip
{
class Program
{
static void Main(string[] args)
{
var l = Console.In.ReadToEnd()
.Split(Environment.NewLine)
.Select(s => s.TrimStart('-'))
.Where(s => s.Contains("IP:"));
foreach (var s in l)
Console.WriteLine(s);
}
}
}
Console.In
. хоть WebResponse.GetResponseStream()
, хоть сокет.Console.In.ReadToEnd().Split(Environment.NewLine)
, вставить File.ReadAllLines("путь+имя")
.StreamReader _reader = new StreamReader(path);
public string GetNext()
{
string line;
while ((line = _reader.ReadLine()) != null)
{
var message = WorkWithLine(line);
if (message != null)
return message;
}
return null;
}
}
public string WorkWithLine(string line)
{
var ip = Regex.Match(line, "IP: .*?\n");
if (ip.Value.Length > 0)
return null;
return ip.Value;
}
Использование:
void Do()
{
string msg;
while(while ((msg = GetNext()) != null)
Console.WriteLine(msg);)
}