The best way to split a string by bracket

D

DAXU

Hi,
If I have string like:
a=(adfd(aa)aa(bb)c(dd))

What is the best way to split the string to:
adfd
(aa)
(bb)
c
(dd)

I can only think of string.split.

Many Thanks

Jerry
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

String.Split will not work here, you will have to make your own rutine. It's
not too dificult just keep the current state (presence of either "(" or
")" ) in a variable and when you find the a new set you know you got another
part.

Make sure to take into account incorrected formed strings like "
adfd(a(a)aa"
 
D

DAXU

Hi,
Thanks. I know I can do it by keep the position of "(" and ")".
What do you think of creating a steate machine to do it? have some
example for me to start with?
Many Thanks
Jerry
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Hi,
Thanks. I know I can do it by keep the position of "(" and ")".
What do you think of creating a steate machine to do it? have some
example for me to start with?
Many Thanks
Jerry

That is the way to go, about examples. well you can always google for them
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top