I have to parse a file that is constructed like this :
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
I need to split every line taking just Name, Last Name and Email into an object of the type
var contact = new Conctact {
Name = fieldFromLine,
Last= fieldFromLine,
Email = fieldFromLine
}
So my problem is which tool use : String.Split or Regex.Split. and how to implement it.
Thank you very much…
This is what a Have done so far:
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...
}
}
1 Answer