Hey everyone I was hoping you could help me with my little problem. I want to split an already split string but I get the error: "The index was outside the bounds of the array".
I know that my array is too small but I don't know how to increase that in this instance. Here is the code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Reserveringssysteem
{
public partial class Form2 : Form
{
public string naam;
public string adres;
public string datum;
public int kamernr;
public int id;
public int indexnr;
public int indexnrb;
public int indexnrc;
Kamer[] reserveringArray = new Kamer[6];
public Form2()
{
InitializeComponent();
}
private void backbtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
using (StreamReader sr = new StreamReader(@"C:\Users\Gebruiker\Desktop\OIS\Hotelsysteem\Reserveringen.txt", Encoding.Default))
{
string text = sr.ReadToEnd();
string[] lines = text.Split(';');
foreach (string s in lines)
{
id = Convert.ToInt32(s.Split(':')[0]);
indexnr = s.IndexOf(':');
naam = s.Split('/')[indexnr];
indexnra = s.IndexOf("/");
adres = s.Split('<')[indexnra];
indexnrb = s.IndexOf('<');
kamernr = Convert.ToInt32(s.Split('>')[indexnrb]);
indexnrc = s.IndexOf('>');
datum = s.Split(';')[indexnrc];
ListViewItem opbouwera = new ListViewItem(Convert.ToString(id));
opbouwera.SubItems.Add(naam);
opbouwera.SubItems.Add(adres);
opbouwera.SubItems.Add(Convert.ToString(kamernr));
opbouwera.SubItems.Add(datum);
reserveringlistview.Items.Add(opbouwera);
}
}
}
}
}
The problem occurs from the moment I start using indexnra
. I hope one of you guys can help me out here.