Solved

String Manipulation

Posted on 2007-03-31
4
253 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:mayankeagle
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 86
How Complex Is This Java Course ? 9 63
word0 challenge 3 58
pairs challenge 5 45
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 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

17 Experts available now in Live!

Get 1:1 Help Now