EDN Admin
Well-known member
The full exception error: Index was out of range. Must be non-negative and less than the size of the collection.<br/>
Parameter name: index
The code:
<pre class="prettyprint" style=" using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<string> dates;
List<string> times;
List<string> texts;
string profileDates;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string fileContent = System.IO.File.ReadAllText(@"d:adilipman1937067724.xml"); // hoe to get the info from the functions still not working.
GetDate(fileContent);
GetTime(fileContent);
GetText(fileContent);
for (int i = 0; i < dates.Count; i++)
{
string fn = dates + " " + times + " " + texts;
textBox1.AppendText(fn + Environment.NewLine);
}
}
private void GetDate(string text)
{
int index;
dates = new List<string>();
string startTag = "Date="";
string endTag = "" Time=";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
dates.Add(profileDates);
}
}
private void GetTime(string text)
{
int index;
times = new List<string>();
string startTag = " Time="";
string endTag = "" DateTime=";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
times.Add(profileDates);
}
}
private void GetText(string text)
{
int index;
texts = new List<string>();
string startTag = "#000000; " + """ + ";
string endTag = "</Text>";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
texts.Add(profileDates);
}
}
}
}[/code]
<br/>
In this case: the variable "i" is 1567
dates Count 1584 , times Count 1584 , texts Count 1567
What i tried to do is to get from a messenger history chat file the date , time and text for each line that have been written. So its working i see it all in the textBox1 but when its finishing loading it to the textBox1 its throwing this exception.
I cant upload here all the messenger history xml file but part of it for example:
<pre class="prettyprint" style=" <?xml version="1.0"?>
<?xml-stylesheet type=text/xsl href=MessageLog.xsl?>
<Log FirstSessionID="1" LastSessionID="2 <Message Date="31/01/2012" Time="10:15:42" DateTime="2012-01-31T08:15:42.467Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000; היי</Text></Message><Message Date="31/01/2012" Time="10:15:55" DateTime="2012-01-31T08:15:55.097Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000; הייתה לי בעיה עם התוכנת ברקים אבל עכשיו הכל עובד.</Text></Message><Message Date="31/01/2012" Time="10:15:58" DateTime="2012-01-31T08:15:58.897Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000;[/code]
<br/>
I tried a lot to parse the text date and time with xmldocument but i didnt understand yet how its working so i did it this way. The only problem is this exception in the end of the process.
<
danieli
<br/>
View the full article
Parameter name: index
The code:
<pre class="prettyprint" style=" using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
List<string> dates;
List<string> times;
List<string> texts;
string profileDates;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string fileContent = System.IO.File.ReadAllText(@"d:adilipman1937067724.xml"); // hoe to get the info from the functions still not working.
GetDate(fileContent);
GetTime(fileContent);
GetText(fileContent);
for (int i = 0; i < dates.Count; i++)
{
string fn = dates + " " + times + " " + texts;
textBox1.AppendText(fn + Environment.NewLine);
}
}
private void GetDate(string text)
{
int index;
dates = new List<string>();
string startTag = "Date="";
string endTag = "" Time=";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
dates.Add(profileDates);
}
}
private void GetTime(string text)
{
int index;
times = new List<string>();
string startTag = " Time="";
string endTag = "" DateTime=";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
times.Add(profileDates);
}
}
private void GetText(string text)
{
int index;
texts = new List<string>();
string startTag = "#000000; " + """ + ";
string endTag = "</Text>";
int startTagWidth = startTag.Length;
int endTagWidth = endTag.Length;
index = 0;
while (true)
{
index = text.IndexOf(startTag, index);
if (index == -1)
{
break;
}
// else more to do - index now is positioned at first character of startTag
int start = index + startTagWidth;
index = text.IndexOf(endTag, start + 1);
if (index == -1)
{
break;
}
// found the endTag
profileDates = text.Substring(start, index - start);
texts.Add(profileDates);
}
}
}
}[/code]
<br/>
In this case: the variable "i" is 1567
dates Count 1584 , times Count 1584 , texts Count 1567
What i tried to do is to get from a messenger history chat file the date , time and text for each line that have been written. So its working i see it all in the textBox1 but when its finishing loading it to the textBox1 its throwing this exception.
I cant upload here all the messenger history xml file but part of it for example:
<pre class="prettyprint" style=" <?xml version="1.0"?>
<?xml-stylesheet type=text/xsl href=MessageLog.xsl?>
<Log FirstSessionID="1" LastSessionID="2 <Message Date="31/01/2012" Time="10:15:42" DateTime="2012-01-31T08:15:42.467Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000; היי</Text></Message><Message Date="31/01/2012" Time="10:15:55" DateTime="2012-01-31T08:15:55.097Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000; הייתה לי בעיה עם התוכנת ברקים אבל עכשיו הכל עובד.</Text></Message><Message Date="31/01/2012" Time="10:15:58" DateTime="2012-01-31T08:15:58.897Z" SessionID="1 <From><User FriendlyName="Chocolade"/></From><To><User FriendlyName="adilipman@yahoo.com"/></To><Text Style="font-family:Segoe UI; color:#000000;[/code]
<br/>
I tried a lot to parse the text date and time with xmldocument but i didnt understand yet how its working so i did it this way. The only problem is this exception in the end of the process.
<
danieli
<br/>
View the full article