Solved

how to split the string

Posted on 2014-07-24
9
141 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

770 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