Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

String Manipulation

Posted on 2007-03-31
4
Medium Priority
?
263 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
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 “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

721 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