|
Hi Richard,
Thanks for your help.I will look at extentreports-dotnet-cli.
|
|
|
|
|
Hi All, I need to parse n lines ( as a block ) from a text file where the start and end blocks are delimited by a marker such as ACC_ID:
ACC_ID:
xxx
...
...
could by dozens of lines
ACC_ID:
xxx
...
etc...
I'm thinking of reading them into a collection of a simple class such as
public class AccountData
{
string Acc_ID {get;set;}
List<string> Data {get;set;}
}
where ACC_ID would contain the start block and the Data would contain all other lines between the start and end block, anyone know of a Linq way of doing this >? I currently do it in a loop reading the file line by line which is fine but I'd like to Linquify it if possible, any ideas ?
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
You have a solution that works and is easily supportable and maintainable. Why would you add complexity and cost by throwing LINQ at it?
|
|
|
|
|
Mainly because I'm learning Linq and this is good real world chance to use it - but I do take your point
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Part of learning LINQ is knowing when NOT to use it.
|
|
|
|
|
I've been in the game long enough to know that
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
I've been in the game long enough to know that
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
I've been in the game long enough to know that
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
Really? 'cause this is one of those times.
|
|
|
|
|
Not really
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
I'd be tempted to just cheat:
string fileContent = File.ReadAllText(@"D:\Temp\AATest.txt");
string[] bits = fileContent.Split(new string[] {"ACC_ID:"}, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in bits)
{
Console.WriteLine("++++");
Console.WriteLine(s);
}
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I'll see how I get on with that cheers mush
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
You can do it in LINQ, but it would probably take more than 1 line.
You have to "normalize" the data before you can query it efficiently.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
I don't mind multi line suggestions
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
You can use 'ReadLines which is designed for this type of scenario: from MS:Quote: When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines, you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, ReadLines can be more efficient.
You can use the ReadLines method to do the following:
Perform LINQ to Objects queries on a file to obtain a filtered set of its lines.
However, keep in mind that you will still have to enumerate at some point: IEnumerables, by design, are not indexed: they are not guaranteed to be ordered.
You can hack up an index facility for IEnumerables [^], but, I have yet to be convinced this is worth much.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I'll look at that thanks Bill
We can’t stop here, this is bat country - Hunter S Thompson RIP
|
|
|
|
|
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.
|
|
|
|
|
i am using a one timer in my application.i need to add 1 of every 100 ms in this application. now the problem is the timer will slowed after some time automatically .
|
|
|
|
|
Show us the relevant code fragments: we can't diagnose coding faults without knowing exactly what you wrote!
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
And explain how you have determined that it is slowing down.
|
|
|
|
|
Timers are not guaranteed to go off "on time" / interval; only that they won't go off earlier.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Windows is not a real-time OS. You will get slices that are guaranteed >100ms, but there's never a guarantee that it is executed within a specific time.
You might want to show some code, and explain which timer you are using; there's a few different ones in the framework.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello,
i am using Visual Studio and C#. I have created a WPF application and i want to read the file.
<window x:class="WpfApplication1.MyDataGrid"
="" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="MyDataGrid" height="300" width="300">
{
InitializeComponent();
var xml = XDocument.Load( "c:\\Desktop\\Data.xml" ).Root;
dataGrid1.DataContext = xml;
}
}
}
No error, just empty DataGrid.
I would be thankful for any help.
regards
modified 26-Jan-19 19:47pm.
|
|
|
|
|
Your first item is called "data", the second "data2"; it should also be called "data", otherwise it is not the same "entity" as the row before and will be seen as something completely new.
Also, don't add the unit-names to the data; choose a single unit and make sure that all measurements are converted to it. So one column for volts, and if you encounter a measurement in milliVolts, you convert it to volts first.
Having a unit in there means that each cell is storing two facts instead of one, and that you can't do aritmethic on it using the normal functions. It would be hear-tearing to work with.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Thank you for the answer.
modified 26-Jan-19 19:47pm.
|
|
|
|