Someone help me with this question please
The test data is whats in the file and has tons of lines of those but i have no idea how to answer this with code, help please!
8 Replies
i suck at file coding
ive got to about here so far but also have no idea how to read each line and move onto the next
and idk how to make each line an array so the split array can split the lines into an array
Just so you know,
File.ReadAllLinesAsync()
will just read the file lines into a string[]
No need for this whole song and dance with streamreader
You will, then, need to parse each line you have
The format seems to be owner:[dog:color,dog:color]
so it should be fairly easy to parse
Split on :
first to get an array of [ owner, dogs ]
then trim [
and ]
from dogs
and split on ,
Then split each dog on :
to get [dog, color]
Ideally, you're looking to parse the file into something like List<Person>
where
Or
Oh, and to loop over all the lines... use a loop
foreach
will work just fine
To split a line you use... .Split()
With a delimiter, of course. For example:Angius
REPL Result: Success
Result: string[]
Compile: 348.807ms | Execution: 23.012ms | React with ❌ to remove this embed.
Huh, now that I look at the format, just splitting on
:
won't be sufficient, since it will split all the dogs as well...
Writing a quick parser would probably be the best, something like...Angius
REPL Result: Success
Result: <>f__AnonymousType0#1<string, string>
Compile: 303.551ms | Execution: 80.188ms | React with ❌ to remove this embed.
oooo ok i think i get what u mean
ill try this out! thank you!!