Solved

how to split the string

Posted on 2014-07-24
9
147 Views
Last Modified: 2014-10-15
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
0
Comment
9 Comments
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40216227
I want yo change that into
No((no(12)+no(5))+no(5)) how do this
0
 
LVL 13

Expert Comment

by:duncanb7
ID: 40216229
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
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 40216238
You can't really handle nesting well with regular expressions. What you're doing is dealing with a mini-language so you need to create a parser for it
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40216309
Praser?? Can you give some example?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216336
0
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40216432
Chj can you tell how implement in my example string
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40216567
Sorry - no. I have no experience with it personally
0
 
LVL 27

Expert Comment

by:rrz
ID: 40217226
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

0
 
LVL 32

Expert Comment

by:awking00
ID: 40220294
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.
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question