• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Please help me

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic