This post originated from an RSS feed registered with Java Buzz
by Padraic R.
Original Post: Commons is your friend
Feed Title: plog
Feed URL: http://sedoparking.com/search/registrar.php?domain=®istrar=sedopark
Feed Description: Padraic Renaghan's musings about (mostly) java software development
Had a task yesterday to strip formatting characters from a string prior
to loading in a database. Figured that was a common function that would
either be in the Java String class or some other widely available 3rd
party class library. Browsed over to the Apache Commons Project and found exactly what I needed. CharSetUtils with the Lang subproject provides a handy delete from string function as well as other useful utility methods.
Have a look for yourself at the Lang subproject and the other Commons subprojects as well -- seems like exactly the kind of drop in library we should all become familiar with to keep ourselves from re-inventing the type of utility classes that seem to be required on every Java development project.
Note: Spent some time trying to debug why this code snippet wouldn't work for removing the dash character from within a formatted phone number:
Turns out the 2nd argument is really a pattern, and "-" is a special character in that pattern indicating a range, so stripping "-" seems impossible with that class - no way to escape the char that I could find. Nevertheless a useful set of methods.