[Archive] Parsing a Line and putting it to array error
[Archive] Parsing a Line and putting it to array error
Archived author: dashker • Posted: 2016-06-06T00:26:59+00:00
Original source
try
{
string ReadedLine = sr.ReadLine();
int resultingname = int.Parse(ReadedLine.Split(',')[0]);
if (race == resultingname)
{
Found = true;
for (int i = 0; i < 69; i++)
{
strvector[i] = ReadedLine.Split(',')[i];
}
}
}
catch (System.FormatException)
{
MessageBox.Show("Fuck You!");
}
When I do this i am having continuosly System.FormatError and i don't know Why ![]()
Thansk for the help
Archived author: Kaev • Posted: 2016-06-06T05:00:02+00:00
Original source
On which line do you get the error? And show us the text that you read.
Quote: 4 hours ago, Kaev1695989297 said:Here you have the code, in theory am making it by a good way but... is failing
On which line do you get the error? And show us the text that you read.
Archived author: dashker • Posted: 2016-06-06T09:12:27+00:00
Original source
Quote: 4 hours ago, Kaev1695989297 said:Here you have the code, in theory am making it by a good way but... is failing
On which line do you get the error? And show us the text that you read.
Archived author: barncastle • Posted: 2016-06-06T10:44:32+00:00
Original source
Try replacing your while clause with the below. I think the problem is that the first field of your csv file isn't an integer and this is where it is breaking - by default DBCUtil adds a header row of column types. To prevent this I've replaced it with TryParse which returns a boolean if it is successful and stores the parsed integer in the resultingname variable.
I've also stored the columns in an array to prevent having to call Split more than once and also to prevent a possible array overflow in your for loop (it should never do so as the dbc file should always have 70 columns).
while (!Found && sr.Peek() != -1)
{
string ReadedLine = sr.ReadLine();
string[] fields = ReadedLine.Split(',');
int resultingname = 0;
if (int.TryParse(fields[0], out resultingname) && race == resultingname)
{
Found = true;
for (int i = 0; i < fields.Length; i++)
strvector[i] = fields[i];
}
}
Quote: 9 hours ago, barncastle said:How i can store it into an array, i need to do an array or a matrix, and how i get the length of a line?
Try replacing your while clause with the below. I think the problem is that the first field of your csv file isn't an integer and this is where it is breaking - by default DBCUtil adds a header row of column types. To prevent this I've replaced it with TryParse which returns a boolean if it is successful and stores the parsed integer in the resultingname variable.
I've also stored the columns in an array to prevent having to call Split more than once and also to prevent a possible array overflow in your for loop (it should never do so as the dbc file should always have 70 columns).
while (!Found && sr.Peek() != -1)
{
string ReadedLine = sr.ReadLine();
string[] fields = ReadedLine.Split(',');
int resultingname = 0;
if (int.TryParse(fields[0], out resultingname) && race == resultingname)
{
Found = true;
for (int i = 0; i < fields.Length; i++)
strvector[i] = fields[i];
}
}
Archived author: dashker • Posted: 2016-06-06T20:06:12+00:00
Original source
Quote: 9 hours ago, barncastle said:How i can store it into an array, i need to do an array or a matrix, and how i get the length of a line?
Try replacing your while clause with the below. I think the problem is that the first field of your csv file isn't an integer and this is where it is breaking - by default DBCUtil adds a header row of column types. To prevent this I've replaced it with TryParse which returns a boolean if it is successful and stores the parsed integer in the resultingname variable.
I've also stored the columns in an array to prevent having to call Split more than once and also to prevent a possible array overflow in your for loop (it should never do so as the dbc file should always have 70 columns).
while (!Found && sr.Peek() != -1)
{
string ReadedLine = sr.ReadLine();
string[] fields = ReadedLine.Split(',');
int resultingname = 0;
if (int.TryParse(fields[0], out resultingname) && race == resultingname)
{
Found = true;
for (int i = 0; i < fields.Length; i++)
strvector[i] = fields[i];
}
}
Archived author: Thoraric • Posted: 2016-06-06T20:15:52+00:00
Original source
The feeling when you open a new post in the hope of learn something new but you don't understand anything. ![]()
Quote: 4 minutes ago, Thoraric said:i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...
The feeling when you open a new post in the hope of learn something new but you don't understand anything.
Archived author: dashker • Posted: 2016-06-06T20:21:18+00:00
Original source
Quote: 4 minutes ago, Thoraric said:i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...
The feeling when you open a new post in the hope of learn something new but you don't understand anything.
Quote: Just now, dashker said:I talked about myself
i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...
Archived author: Thoraric • Posted: 2016-06-06T20:22:20+00:00
Original source
Quote: Just now, dashker said:I talked about myself
i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...
Quote: Just now, Thoraric said:ah okay hahahah sorry
I talked about myself
Archived author: dashker • Posted: 2016-06-06T20:23:21+00:00
Original source
Quote: Just now, Thoraric said:ah okay hahahah sorry
I talked about myself
Quote: Just now, dashker said:np
ah okay hahahah sorry
Archived author: Thoraric • Posted: 2016-06-06T20:23:46+00:00
Original source
Quote: Just now, dashker said:np
ah okay hahahah sorry