Solved

String Manipulation

Posted on 2007-03-31
4
256 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 51
servlet requestdispatcher include and forward differences 1 30
egit plugin on eclipse 8 62
by zero exception 10 39
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 second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 video teaches viewers about errors in exception handling.

785 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