I have a code-like string like the following:
a
{
bcd
{
ef
{
gh
{
i
}
j
}
}
k
{
lmn
{
op
}
qr
{
st
}
uv
{
wx
}
y
}
z
}
I wish to parse this string such so that I can create a hierarchical array from this code where each tree gets created based on {
and a tree ends at }
.
The array would look like:
[
"a",
"{",
[
"bcd",
"{",
[
"ef",
"{",
[
"gh",
"{",
[
"i"
],
"}",
"j"
],
"}"
],
"}",
"k",
"{",
[
"lmn",
"{",
[
"op"
],
"}",
"qr",
"{",
[
"st"
],
"}",
"uv",
"{",
[
"wx"
],
"}",
"y"
],
"}",
"z"
],
"}"
]
Can any one help me in getting an algo of this?
You can also pass me a code in any of these languages Java/C#/PHP/VB.NET/JavaScript/ActionScript.