Link to home
Start Free TrialLog in
Avatar of DrAske
DrAskeFlag for Jordan

asked on

String Manipulation

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?
Avatar of Mayank S
Mayank S
Flag of India image

Maybe try using the split () method where you can.
Avatar of DrAske

ASKER

could you please explain more??
ASKER CERTIFIED SOLUTION
Avatar of cavey_79
cavey_79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DrAske

ASKER

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

thank you :o)
regards,