Solved

String Manipulation

Posted on 2007-03-31
4
262 Views
Last Modified: 2010-03-31
Hi Experts ..

I'm writing a method to make some manipulations on a *String*, and there is 2D integer array, each row in this 2D array represents the first index,last index of substring of the given string to apply some changes on it.
e.g:
String input = "Experts-Exchange ";
int[][] parts = <<invoke method that returns the specified parts>>
now
for(int i = 0; i<parts.length; ++i){
                sb.append(input.substring(0,parts[i][0])); // append the part before the substring
                String str = <<invoke method that do some changes on the substring(input.substring(parts[i][0], parts[i][1])) may be convert it to upper case, lower case, replacing, or whaterver>>
                sb.append(str); // the manipulated string
                sb.append(input.substring(parts[i][1])); // the part after the manipulated string
                input = sb.toString();
                sb.delete(0, sb.length());
            }
I'm posting here cause I couldn't find a better way to tokenize the string and join it again ..
so, I want your opinion about the code I've posted?? or if you've a better way to do that?
0
Comment
Question by:DrAske
[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
  • 2
4 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18829212
Maybe try using the split () method where you can.
0
 
LVL 9

Author Comment

by:DrAske
ID: 18829233
could you please explain more??
0
 
LVL 3

Accepted Solution

by:
cavey_79 earned 500 total points
ID: 18836918
There is no better way to do it. split() will work if you just want to split it based on some regex, but it will be slower for simple cases since it uses regex.

You could try looking into StringUtils here:
http://jakarta.apache.org/commons/lang/api-release/org/apache/commons/lang/StringUtils.html
but that will just make your code safer, the approach will still be the same.
0
 
LVL 9

Author Comment

by:DrAske
ID: 18837846
I don't want to use any external packages, there is restriction for that, so I can't use it.

thank you :o)
regards,
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

630 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