我必须解析一个像这样构造的文件:
User: jcruz Name: Jules Last: Cruz Email: Some@email.com
User: jdoe Name: John Last: Doe Email: Some@email.com
User: pmartin Name: Pete Last: Martin Email: Some@email.com
User: rrichard Name: Reed Last: Richard Email: Some@email.com
我需要将仅包含姓名、姓氏和电子邮件的每一行拆分为类型的对象
var contact = new Conctact {
Name = fieldFromLine,
Last= fieldFromLine,
Email = fieldFromLine
}
所以我的问题是使用哪个工具 :String.Split
或Regex.Split
. 以及如何实施。
非常感谢你...
这是迄今为止所做的:
String archivo = ((FileDialog)sender).FileName;
using (TextReader sr = new StreamReader(archivo,Encoding.UTF8))
{
String line = String.Empty;
while ((line = sr.ReadLine()) != null )
{
string[] result = Regex.Split(line,"User:");
//How to get the other fields...
}
}