need some help with Lists

  • Thread starter Thread starter jtfry03
  • Start date Start date
J

jtfry03

Guest
I am running into trouble with this program. For some reason I am getting an Index out of bounds error

I am not sure why. It was written in C#. Suggestions would be nice.

NOTE. the file is a .CSV. and var L is one outlined box.

lines is defined as follows...

string line = string.Empty;
List<string[]> lines = new List<string[]>();

if(args.Length < 1) while((line = Console.ReadLine()) != null) lines.Add(line.Split(','));
else {
foreach(var l in File.ReadAllLines(args[0])) {
lines.Add(l.Split(','));
}
}


The line I am having trouble with is

int.Parse(lines[2][2].Replace("bpm", string.Empty))


public static void Main(string[] args) {
string line = string.Empty;
List<string[]> lines = new List<string[]>();

if(args.Length < 1) while((line = Console.ReadLine()) != null) lines.Add(line.Split(','));
else {
foreach(var l in File.ReadAllLines(args[0])) {
lines.Add(l.Split(','));
}
}
//Console.WriteLine(args[0]);Console.ReadLine();return;
quarterNoteBPM = int.Parse(lines[2][2].Replace("bpm", string.Empty));
int firstNoteLineID = getFirstNoteIndex(lines);
// skip the header and go directly to the notes
var linesWithNotes = lines.Skip(firstNoteLineID).ToList();
//Console.WriteLine(lines[0][1]);
//Console.ReadLine();
//return;
var sb = new StringBuilder();
sb.Append(header);
var linesID = 0;
int failsafe = 0;
//Console.WriteLine(args[0]);Console.ReadLine();
for(int loopID = 0; linesID < linesWithNotes.Count; loopID++) {
failsafe++; if(failsafe > 100) break;
if(loopID == 64) {
loopID = 0;
patternCount++;
sb.Append(patternTitle.Replace("XX", patternCount.ToString("X").PadLeft(2, '0')));
}

Continue reading...
 
Back
Top