Basically, I am wondering if there is a handy class or method to filter a String for unwanted characters. The output of the method should be the 'cleaned' String. I.e.:
String dirtyString = "This contains spaces which are not allowed"
String result = cleaner.getCleanedString(dirtyString);
Expecting result would be:
"Thiscontainsspaceswhicharenotallowed"
A better example:
String reallyDirty = " this*is#a*&very_dirty&String"
String result = cleaner.getCleanedString(dirtyString);
I expect the result to be:
"thisisaverydirtyString"
Because I let the cleaner know that ' ', '*', '#', '&' and '_' are dirty characters. I can solve it by using a white/black list array of chars. But I don't want to re-invent the wheel.
I was wondering if there is already such a thing that can 'clean' strings using a regex instead of writing this myself.
Addition:
- If you think cleaning a String could be done differently/better then I am, all ears as well of course.
Another addition:
- It is not only for spaces, but for any kind of 'dirty' characters.