UPDATE:
I did not realise that Thomas Levesque had posted a solution and worked on my own below one in the meantime. I’m not using C# / VS2010 for long but I must say that C# is unbelievably productive and I am kicking myself that I stuck with C++ and put off learning C# for so long.
Stack<string> LdifUserStack = new Stack<string>();
String LdifValidUser = null;
var query2 = File.ReadAllLines(args[1]).ToList();
foreach (var item in query2)
{
if ( item.Contains("Fullname") ) continue;
LdifValidUser += item + System.Environment.NewLine;
if ( LdifValidUser.Contains("GivenName:") && LdifValidUser.Contains("SN:") )
{
LdifUserStack.Push(LdifValidUser);
LdifValidUser = null;
}
else if ( string.IsNullOrEmpty(item) )
{
LdifValidUser = null;
}
}
END UPDATE:
I have a simple ldif file and I am trying to split on /r/n/r/n but no joy, whatever combination i use the split always occurs on each line instead.
var query2 =
from line in File.ReadAllLines(args[1])
let LDIFRecord = line.Split(new string[] { "\r\n\r\n"},StringSplitOptions.None)
select LDIFRecord;
foreach (var item in query2)
{
//do something
}
//Also tried line.Split(new string[] {"'\r\n','\r\n'"},StringSplitOptions.None)
// sample ldif file
dn: cn=Admin1,ou=abt,o=cach
changetype: modify
GivenName: Admin
Fullname: Administrator for abt Server
SN: Admin
CN: Admin
dn: cn=admin,ou=ters,o=cach
changetype: modify
GivenName: Administrator
Fullname: cach Administrator
SN: admin
CN: admin
dn: cn=Supervisor,o=cach
changetype: modify
SN: Supervisor
CN: Supervisor