Solved

String Manipulation

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
throw exception 21 58
JavaFX TableView not displaying correctly 3 54
eclipse console opening separately 2 29
collection output issue 9 36
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This video teaches viewers about errors in exception handling.

809 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