dashker Posted June 6, 2016 Share Posted June 6, 2016 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 Link to comment Share on other sites More sharing options...
Kaev Posted June 6, 2016 Share Posted June 6, 2016 On which line do you get the error? And show us the text that you read. Link to comment Share on other sites More sharing options...
dashker Posted June 6, 2016 Author Share Posted June 6, 2016 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 Link to comment Share on other sites More sharing options...
barncastle Posted June 6, 2016 Share Posted June 6, 2016 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]; } } Link to comment Share on other sites More sharing options...
dashker Posted June 6, 2016 Author Share Posted June 6, 2016 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? Link to comment Share on other sites More sharing options...
Thoraric Posted June 6, 2016 Share Posted June 6, 2016 The feeling when you open a new post in the hope of learn something new but you don't understand anything. Link to comment Share on other sites More sharing options...
dashker Posted June 6, 2016 Author Share Posted June 6, 2016 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. i am understanding it, but never used this things, and minus in class, so i need help to learn, i think it's normal... Link to comment Share on other sites More sharing options...
Thoraric Posted June 6, 2016 Share Posted June 6, 2016 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 Link to comment Share on other sites More sharing options...
dashker Posted June 6, 2016 Author Share Posted June 6, 2016 Just now, Thoraric said: I talked about myself ah okay hahahah sorry Link to comment Share on other sites More sharing options...
Thoraric Posted June 6, 2016 Share Posted June 6, 2016 Just now, dashker said: ah okay hahahah sorry np Link to comment Share on other sites More sharing options...
barncastle Posted June 7, 2016 Share Posted June 7, 2016 I might be missing something but your current code will only return one record and stores it in strvector which is already an array? If you want to parse the entire CSV you'll need something like a list or dictionary and add strvector to it each time it reads a line - you'll need to remove the Found check for that. To get column count you could do something like ReadedLine.Split(',').Length. To get the a row's field count do the same on strvector i.e. strvector.Length. Link to comment Share on other sites More sharing options...
dashker Posted June 7, 2016 Author Share Posted June 7, 2016 thanks, :3 Link to comment Share on other sites More sharing options...
Parsing a Line and putting it to array error
By dashkerin Miscellaneous
Recommended Posts