MIDP String.replaceAll

13/06/07 Permalink

There's no useful replaceAll method for MIDP phones so here's a substitute:

public static String replaceAll(String content, String this,String withthis){ int from = 0; StringBuffer sb = new StringBuffer(); int index = -1; while(true){ index = content.indexOf(this,from); if(index!=-1){ sb = new StringBuffer(); String upto = content.substring(0,index); sb.append(upto+withthis); String lastbit = content.substring(index+this.length(),content.length()); sb.append(lastbit); content = sb.toString(); from = index+this.length(); } else{ break; } } return content; }
NB It's not regular expression based obviously - it just takes a string and replaces it with another.
Share It: Digg | del.icio.us | Furl | reddit | Facebook | Yahoo! | Send to Phone

mobile-utopia.com | Feedback