0

So, before I describe my problem you need some context: I have some custom file that describe some objects by text. One of the lines of this file looks like this:

...
~
InWalls:
[0](Name = "Wall", Pos = 1|2, Rot = 7)
~
...

my program reads this file like so

  1. join all lines in file

  2. delete all spaces

  3. split line by "~"

  4. for(each line)

    4.1 split by ":"

    4.2 swith on first (in this case it's "InWalls")

    4.3 find in second "(", ")" and substring between (we get "Name = "Wall", Pos = 1|2, Rot = 7")

    4.4 split by ","

    4.5 each split by "="

    4... do staff and so on..

Really simple concept, isn't? Basically, as you understand, I use String.Split() and String.SubString() a lot, and everything working.. BUT!! What if my string looks like this..

...
~
InWalls:
[0](Name = "Wall (1)", Pos = 1|2, Rot = 7)
~
...

here on step 4.3 I will get not "Name = "Wall (1)", Pos = 1|2, Rot = 7", BUT "Name = "Wall (1", and I don't know how to fix this.. I need property "Name", and I can't just cut off this part... Does some has any thoughts on that?

Vlad
  • 113
  • 2
  • 9
  • 1
    We need actual code, input/output examples. Please include a [MCVE] with your question – maccettura Aug 03 '18 at 18:53
  • Escape the strings before writing them, de-escape after reading. For example %28 = ( , %29 = ) and %% for %. – Dave S Aug 03 '18 at 18:59
  • 1
    Things that have matching "opening" and "closing" "delimiters" need a **stack** to "parse" properly. [Distantly related](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags). [Beginning study material](https://en.wikipedia.org/wiki/Regular_language). – Vanity Slug - codidact.com Aug 03 '18 at 19:00
  • 1
    How sold are you on that syntax? Why not use a similar standard syntax like JSON that already has parsers written? – D Stanley Aug 03 '18 at 19:42

0 Answers0