Solved

how to split the string

Posted on 2014-07-24
9
149 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

691 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