C# Parsing Text File question?
Alright so relating to a code which is working wonderful except it’s got one problem I can’t seem to repair.
I’m parsing a comma delimited textual content file which has 8 commas seperating data on each and every line.
I’m adding the knowledge that my partner and i extract to an array.
However here are a few lines between the word file which might be simply just one word which has no commas.
This includes an ‘Index outside bounds’ error once the code can’t find a comma on that particular line.
Case:
info1, info2, info3, info4, info5, info6, info7, info8, info9
info1, info2, info3, info4, info5, info6, info7, info8, info9
Randomword
info1, info2, info3, info4, info5, info6, info7, info8, info9
The signal ignores info1 and the index0 starts at data 2.
When the item reaches “Randomword” there’s no comma in order to assign index0 that will.
Is there ways to ignore every line starting up with “Randomword”
Here is an example of my rule:
StreamReader FileStreamReader = different StreamReader(“CombatLog.txt”);
stringed damaging = “damage”, “hits”;
int dps = 0;
although (FileStreamReader.Peek()! = -1)
stringed words;
terms = FileStreamReader.ReadLine().Split(‘, ‘);
if (words5.Trim() == “Jeff”)
if (damaging.Any(s => words9.Contains(s)))
dps = dps + Replace.ToInt32(words7.Trim());
You could look at along words following your Split.If it isn’t 9, dismiss the tier:
terms = FileStreamReader.ReadLine().Split(‘, ‘);
if(x.Size! = 9)
continue; // Choose read the next line.
Don’t try a streamreader in addition to array.Hook up to the wording file implementing OLEDB by means of treating the textfile to be a table in addition to load that textfile in to a datatable, you then can only right a great SQL statement or LINQ report to remove the Rows which have Randomword.
Leave a Reply
You must be logged in to post a comment.