I am trying to use a method replaceAll in my Java 2 ME midlet, but recently found out, that there isn't such option. I was trying to recreate the method, but with no luck. Here is the code I tried:
public static String myReplaceAll(String str,String pattern,String replace ){
int s =0;
int e =0;
StringBuffer result = new StringBuffer();
while((e = str.indexOf( pattern, s ))>=0){
result.append(str.substring( s, e ));
result.append( replace );
s = e+pattern.length();
}
result.append( str.substring( s ));
return result.toString();
}
When I try to run this code:
String pokus = "T+e+s+t č 1";
String test = myReplaceAll(pokus,"[^ A-Za-z0-9]","");
System.out.println(test);
It returns without changing. Is there a mistake in the code or does it not recognize "[^ A-Za-z0-9]" this part?