Answer the question
In order to leave comments, you need to log in
How to parse text file format?
Hello everyone
, Please tell me how to parse this file format:
string:
substring1
substring2
substring3
substring4
substring5
string1:
substring1-1
substring2-1
substring3-1
substring4-1
substring5-1
Answer the question
In order to leave comments, you need to log in
Is this YAML
by any chance ?
If yes, then https://godoc.org/gopkg.in/yaml.v2
What is the file extension?
1 loop and 1 flag and one relatively complex condition (regexp will be handy).
We reset the flag to its original state (in Go it is enough to declare it, there is automatic initialization of variables)
The cycle is like this - we read until the file is over
. regexp)
If the string is such, then we go to the second state, and the found string will be a new branch of the tree.
If the string is not the same, then an error
If the state is the second, then we compare for the same condition
If it matches, then we return to the first state
If it does not match, then we place the current string in the current branch of the tree.
This is a common programming task.
This does not require any libraries (except regular ones).
There are no tricky algorithms here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question