|
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.
|
|
|
|
|
Is not valid XML, so won't work.
XML Validator[^]
Try starting and experimenting with a simpeler example.
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.
|
|
|
|
|
This xml was created from a programm i am using. There are no empty lines, its all in 1 line, no space. But the rest is really the same.
|
|
|
|
|
Then the program is creating non-valid XML. If you open a tag, you need to close it; the amount of < is larger than the amount of >.
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.
|
|
|
|
|
The number of opening is sure the same like closing, i have seen i have forgotten one / at the end /Group. but
<systemm> for example appears 1 time there.
|
|
|
|
|
So you changed the XML five minutes ago. It contained an "<blabla <somethingelse=""> ", which isn't allowed. I added the link to the validator so you can validate it yourself. The new example (which I applaud the program for changing so quickly) bis also invalid XML. Spaces aren't allowed in tagnames.
--edit
This was the original example, where the validator pointed out the mismatching opening/closing tags.
<Students Variable="Age"
<Semester>2</Semester>
</Students>
<Students Variable="Age"
<Semester>3</Semester>
</Students>
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.
|
|
|
|
|
Yes, i didn't make copy and paste i have typed it. I am sorry because of the error, there is really no space in tagname. If its that line, its sure correct, .. now
|
|
|
|
|
1) Unless it's a user control, you almost never use a StackPanel as a "top" content control (of a window); you usually use a Grid; 2 columns in your case. (StackPanels tend to stretch beyond the client area if not "contained").
2) You're confusing the "DataContext" (of a UI Element) with the "ItemSource" of a list-type control.
c# - Show the contents of xml file in wpf window - Stack Overflow
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
how to work with ms word add in in c# and how to get data from exel(using excel as database)
|
|
|
|