0

This is my source string

substrb ( userenv ( 'CLIENT_INFO' ) , 1 , 1 ) , '' , null , substrb ( 'some_text'  , 1 , 10 ) 

I want to tokenize it in the following form

[1] : substrb ( userenv ( 'CLIENT_INFO' ) , 1 , 1 )
[2] : ''
[3] : null
[4] : substrb ( 'some_text'  , 1 , 10 )

Any Idea how to do it?

Thank you

1 Answer 1

5

I would advise writing a parser for this. All you need to do is count the number of currently open brackets and cut the string if there is a comma and the counter is at 0.

Something along the line of this:

int openBrackets = 0;
ArrayList<String> tokens = new ArrayList<String>();
StringBuilder tmp = new StringBuilder();
for (int i = 0; i < inputString.length; ++i) {
   char cc = inputString.charAt(i);
   if (cc == '(') openBrackets++;
   else if (cc == ')') openBrackets--;
   else if ((cc == ',') && (openBrackets == 0)) {
      tokens.add(tmp.toString());
      tmp.delete(0, tmp.length());
   }
   else tmp.append(cc);
}
if (tmp.length() > 0) tokens.add(tmp.toString());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.