Solved

how to split the string

Posted on 2014-07-24
9
139 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
 
LVL 20

Author Comment

by:Sathish David Kumar N
ID: 40216309
Praser?? Can you give some example?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now