asdasdasd
asdasdasd

Reputation: 43

parsing a string which has parenthesis and comma seperated values

i have a string like this:

string astr = "a(b,c,u),d,e(f),g(),h,i(j(k,l,m(n))),r";

you can think this as a file system
on the input letters which has () is folders
remains are the files
whats correct way to parse this string
regex , stack function or simple string parse functions ? and how ?

Upvotes: 2

Views: 197

Answers (1)

Alper Fırat Kaya
Alper Fırat Kaya

Reputation: 2359

i think simple stack and string methods would be enough go through every character on string make a stack named url when you see "(" ")" or "," character parse it when you see "(" character push the x( x to stack when you see ")" character pop the stack

and you will have a token with its url to where it belongs

Upvotes: 1

Related Questions