java - String.replaceAll does not apply to any kind of characters -


this question has answer here:

so i've got simple method should remove characters except upper , lowercase letters , numbers string.

public static string tosimple(string arg) //redurziert einen string auf buchstaben und ganze zahlen {     string string = arg;     int = 0;     while ( < string.length())     {         if (((int)string.charat(i) >= 48 && (int)string.charat(i) <= 57)||((int)string.charat(i) >= 65 && (int)string.charat(i) <= 90)||((int)string.charat(i) >= 97 && (int)string.charat(i) <= 121))             i+=1;         else         {             int = string.length();             string = string.replaceall(""+string.charat(i), "");              if (!(string.length() < a)) //just in case             {                 i+=1;             }         } 

the problem in cases string.replaceall won't change though reached , given character. checked in debugger , couldn't find apparent errors or exceptions. didn't check whole ascii table, know problem occur '$' '?' , '.'. suggestions how solve that?

string.replaceall takes regular expression first parameter.

$, ? , . special characters in regular expressions.

use string.replace instead - uses regular expressions internally too, escapes strings correctly.


however, given you're using string.replaceall, can use regular expression whole thing:

return arg.replaceall("[^a-za-z0-9]", ""); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -