Solved

how to split the string

Posted on 2014-07-24
9
136 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 31

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

747 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

13 Experts available now in Live!

Get 1:1 Help Now