Link to home
Start Free TrialLog in
Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on

how to split the string

Hi i have ah string like this

String s = add(add(12,5),5)
I want to split this first i want to do inside add then come to out side
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

ASKER

I want yo change that into
No((no(12)+no(5))+no(5)) how do this
Avatar of duncanb7
duncanb7

Why you mention split string ? If using split() to split string with delimiter
of "-",for example, the code will be this

String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 0

Open in new window


Could you write it more and in detail

Duncan
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Praser?? Can you give some example?
Chj can you tell how implement in my example string
Sorry - no. I have no experience with it personally
If you want
add(add(12,5),5)  to change to  No((no(12)+no(5))+no(5))      
import java.util.regex.*;
public class Test {
   public static void main(String args[]){
    String s = "add(add(12,5),5)";
	Pattern p = Pattern.compile("-?\\d+");
        Matcher m = p.matcher(s);
	StringBuilder sb = new StringBuilder("No((");
	while (m.find()) {
		sb.append("no(" + m.group() + ")+");
	}
	sb.deleteCharAt(sb.length() - 1);
	sb.append(")");
    System.out.print(sb.toString());
   }
}

Open in new window

I suspect your example is a sample representation of some real data that probably has more than one variation. Perhaps you can provide some different samples and, most importantly, an explicit explanation of the criteria to employ to produce your desired results.