Can anyone tell me how to remove all non-number characters from a string such as a tel. number before it is inserted into a database?
Thank you. :confused: :o
Printable View
Can anyone tell me how to remove all non-number characters from a string such as a tel. number before it is inserted into a database?
Thank you. :confused: :o
Use a StringBuffer. Loop through the tel num String and append each numerical character (test with Character.isDigit(ch)) to the StringBuffer. Use the content of the StringBuffer as the value for the database field.
The same will work with StringBuilder, which provides the same functionality at a faster speed (unless you need to work with threads and this method has to be synchronized).