C
C#2y ago
morry329#

❔ input string is not correct format

Context: I was playing around the advent-of-code posted by someone else, a line of his code kept giving me this error ìnput string is not correct format I tried tryparse etc but to no avail. The precise error position is at line 15
var targetY = int.Parse(data[0]);
var targetY = int.Parse(data[0]);
the full code is here: https://github.com/bradwilson/advent-2022/blob/main/day15/Program.cs I read a lot of SO posts about the input not converted to int (which triggered the error) , but here he uses
[0]
[0]
so would it be enough for the input to be parsed int? (this is my uneducated guess)
GitHub
advent-2022/Program.cs at main · bradwilson/advent-2022
Advent of Code 2022 (C# 11/.NET 7). Contribute to bradwilson/advent-2022 development by creating an account on GitHub.
6 Replies
Aaron
Aaron2y ago
data[0] is the entire first line of the input file you can do Console.WriteLine(data[0]); before the Parse to see it
Thinker
Thinker2y ago
More specifically, that exception occurs whenever you try to parse a string which cannot be parsed for one reason or another.
MODiX
MODiX2y ago
thinker227#5176
REPL Result: Failure
int.Parse("a")
int.Parse("a")
Exception: FormatException
- The input string 'a' was not in a correct format.
- The input string 'a' was not in a correct format.
Compile: 427.780ms | Execution: 27.529ms | React with ❌ to remove this embed.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
morry329#
morry329#OP2y ago
Oh yes, I confirmed that by doing
Console.WriteLine(data[0]);
Console.WriteLine(data[0]);
. My uneducated guess is now that I need to parse the entire input of the var data then? If so, could you kindly give me some hints to parse the entire var, not just the first line [0]? 🤦
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server