Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me

 
Garry Kalra
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell me how to do this. I've got a String named schoolName as
String schoolName = "[School][Category][Type]";
I want to convert all those [ in the string to [= and all
tose ] to +]. Please tell me if there is a function to do so. I
understand that i can do so by scanning through the String, but i
need a function that replaces a single character with a string.
Hope i have made myself clear, if not still, please tell me.
Gaurav Kalra
 
k b
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
// Here is a method that can help your problem

private String replaceText(String orig, char c, String s){
String modified =orig;
while(orig.indexOf(c) != -1){
int index = orig.indexOf(c);
modified = orig.substring(0,index) + s + orig.substring(index+1);
orig = modified;
}
return modified;
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic