Forums WoW Modding Discussion Miscellaneous [Archive] Parsing a Line and putting it to array error

[Archive] Parsing a Line and putting it to array error

[Archive] Parsing a Line and putting it to array error

Pages (2): 1 2 Next
rektbyfaith
Administrator
0
06-06-2016, 12:26 AM
#1
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 [Image: sad.png]

Thansk for the help
rektbyfaith
06-06-2016, 12:26 AM #1

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 [Image: sad.png]

Thansk for the help

rektbyfaith
Administrator
0
06-06-2016, 05:00 AM
#2
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.
rektbyfaith
06-06-2016, 05:00 AM #2

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.

rektbyfaith
Administrator
0
06-06-2016, 09:12 AM
#3
Archived author: dashker • Posted: 2016-06-06T09:12:27+00:00
Original source

Quote: 4 hours ago, Kaev1695989297 said:

On which line do you get the error? And show us the text that you read.
Here you have the code, in theory am making it by a good way but... is failing

ReadChrRaces.cs
rektbyfaith
06-06-2016, 09:12 AM #3

Archived author: dashker • Posted: 2016-06-06T09:12:27+00:00
Original source

Quote: 4 hours ago, Kaev1695989297 said:

On which line do you get the error? And show us the text that you read.
Here you have the code, in theory am making it by a good way but... is failing

ReadChrRaces.cs

rektbyfaith
Administrator
0
06-06-2016, 10:44 AM
#4
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];
}
}
rektbyfaith
06-06-2016, 10:44 AM #4

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];
}
}

rektbyfaith
Administrator
0
06-06-2016, 08:06 PM
#5
Archived author: dashker • Posted: 2016-06-06T20:06:12+00:00
Original source

Quote: 9 hours ago, barncastle said:

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];
}
}
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?
rektbyfaith
06-06-2016, 08:06 PM #5

Archived author: dashker • Posted: 2016-06-06T20:06:12+00:00
Original source

Quote: 9 hours ago, barncastle said:

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];
}
}
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?

rektbyfaith
Administrator
0
06-06-2016, 08:15 PM
#6
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. [Image: biggrin.png]
rektbyfaith
06-06-2016, 08:15 PM #6

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. [Image: biggrin.png]

rektbyfaith
Administrator
0
06-06-2016, 08:21 PM
#7
Archived author: dashker • Posted: 2016-06-06T20:21:18+00:00
Original source

Quote: 4 minutes ago, Thoraric said:

The feeling when you open a new post in the hope of learn something new but you don't understand anything. [Image: biggrin.png]
i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...
rektbyfaith
06-06-2016, 08:21 PM #7

Archived author: dashker • Posted: 2016-06-06T20:21:18+00:00
Original source

Quote: 4 minutes ago, Thoraric said:

The feeling when you open a new post in the hope of learn something new but you don't understand anything. [Image: biggrin.png]
i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal...

rektbyfaith
Administrator
0
06-06-2016, 08:22 PM
#8
Archived author: Thoraric • Posted: 2016-06-06T20:22:20+00:00
Original source

Quote: Just now, dashker 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...
I talked about myself
rektbyfaith
06-06-2016, 08:22 PM #8

Archived author: Thoraric • Posted: 2016-06-06T20:22:20+00:00
Original source

Quote: Just now, dashker 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...
I talked about myself

rektbyfaith
Administrator
0
06-06-2016, 08:23 PM
#9
Archived author: dashker • Posted: 2016-06-06T20:23:21+00:00
Original source

Quote: Just now, Thoraric said:

I talked about myself
ah okay hahahah sorry [Image: sad.png]
rektbyfaith
06-06-2016, 08:23 PM #9

Archived author: dashker • Posted: 2016-06-06T20:23:21+00:00
Original source

Quote: Just now, Thoraric said:

I talked about myself
ah okay hahahah sorry [Image: sad.png]

rektbyfaith
Administrator
0
06-06-2016, 08:23 PM
#10
Archived author: Thoraric • Posted: 2016-06-06T20:23:46+00:00
Original source

Quote: Just now, dashker said:

ah okay hahahah sorry [Image: sad.png]
np [Image: biggrin.png]
rektbyfaith
06-06-2016, 08:23 PM #10

Archived author: Thoraric • Posted: 2016-06-06T20:23:46+00:00
Original source

Quote: Just now, dashker said:

ah okay hahahah sorry [Image: sad.png]
np [Image: biggrin.png]

Pages (2): 1 2 Next
Recently Browsing
 1 Guest(s)
Recently Browsing
 1 Guest(s)