DrAske
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?
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(
String str = <<invoke method that do some changes on the substring(input.substring(
sb.append(str); // the manipulated string
sb.append(input.substring(
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?
Maybe try using the split () method where you can.
ASKER
could you please explain more??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,
thank you :o)
regards,