Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Read n lines from file Pin
pkfox30-Jan-19 8:06
professionalpkfox30-Jan-19 8:06 
AnswerRe: Read n lines from file Pin
OriginalGriff28-Jan-19 4:39
mveOriginalGriff28-Jan-19 4:39 
GeneralRe: Read n lines from file Pin
pkfox28-Jan-19 21:16
professionalpkfox28-Jan-19 21:16 
AnswerRe: Read n lines from file Pin
Gerry Schmitz28-Jan-19 8:13
mveGerry Schmitz28-Jan-19 8:13 
GeneralRe: Read n lines from file Pin
pkfox28-Jan-19 21:17
professionalpkfox28-Jan-19 21:17 
AnswerRe: Read n lines from file Pin
BillWoodruff28-Jan-19 23:43
professionalBillWoodruff28-Jan-19 23:43 
GeneralRe: Read n lines from file Pin
pkfox30-Jan-19 7:50
professionalpkfox30-Jan-19 7:50 
AnswerRe: Read n lines from file Pin
AFell231-Jan-19 6:24
AFell231-Jan-19 6:24 
Here is perhaps the best way to handle this using Linq expressions:

static List<AccountData> ParseAccountData(string filePath, string delimiter = "ACC_ID:")
{
	int g = 0;
	return File.ReadAllLines(filePath)
		.Select(x => new 
		{ 
			group = x == delimiter ? ++g : g,
			line = x 
		})
		.Where(x => x.line != delimiter)
		.GroupBy(x => x.group)
		.Select(x => new AccountData 
		{ 
			Acc_ID = x.First().line,
			Data = x.Skip(1).Select(z => z.line).ToList()
		})
		.ToList()
}

class AccountData
{
	public string Acc_ID { get; set; }
	
	public List<string> Data { get; set; }
}

As you can see, it's not a one-liner, but it can be a bit more succinct than a looping statement. From a performance perspective, it's probably not that much faster. And the File.ReadAllLines method can be bad for memory usage for parsing exceptionally large files.
QuestionTimer is get slowed after some time Pin
Mohamed Fahad26-Jan-19 1:01
Mohamed Fahad26-Jan-19 1:01 
AnswerRe: Timer is get slowed after some time Pin
OriginalGriff26-Jan-19 4:11
mveOriginalGriff26-Jan-19 4:11 
AnswerRe: Timer is get slowed after some time Pin
jschell26-Jan-19 7:00
jschell26-Jan-19 7:00 
AnswerRe: Timer is get slowed after some time Pin
Gerry Schmitz26-Jan-19 8:35
mveGerry Schmitz26-Jan-19 8:35 
AnswerRe: Timer is get slowed after some time Pin
Eddy Vluggen26-Jan-19 8:56
professionalEddy Vluggen26-Jan-19 8:56 
QuestionHow to read a xml file with WPF and unkown amount of data Pin
Member 1413010725-Jan-19 8:57
Member 1413010725-Jan-19 8:57 
AnswerRe: How to read a xml file with WPF and unkown amount of data Pin
Eddy Vluggen26-Jan-19 0:10
professionalEddy Vluggen26-Jan-19 0:10 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Member 1413010726-Jan-19 5:21
Member 1413010726-Jan-19 5:21 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Eddy Vluggen26-Jan-19 8:46
professionalEddy Vluggen26-Jan-19 8:46 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Member 1413010726-Jan-19 8:51
Member 1413010726-Jan-19 8:51 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Eddy Vluggen26-Jan-19 8:55
professionalEddy Vluggen26-Jan-19 8:55 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Member 1413010726-Jan-19 9:02
Member 1413010726-Jan-19 9:02 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Eddy Vluggen26-Jan-19 9:13
professionalEddy Vluggen26-Jan-19 9:13 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Member 1413010726-Jan-19 9:21
Member 1413010726-Jan-19 9:21 
AnswerRe: How to read a xml file with WPF and unkown amount of data Pin
Gerry Schmitz26-Jan-19 8:52
mveGerry Schmitz26-Jan-19 8:52 
GeneralRe: How to read a xml file with WPF and unkown amount of data Pin
Member 1413010726-Jan-19 12:22
Member 1413010726-Jan-19 12:22 
Questionc# Pin
Member 1412841524-Jan-19 0:36
Member 1412841524-Jan-19 0:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.