• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to remove Numeric values from a String  RSS feed

 
Phani Kiran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement where i get values such as db1,tl1,pm100,dev78 from the databse into a drop down box but while taking the value i need to take it as only db,tl,pm,dev.

Can anyone give me a java method to remove the numeric values in the String obtained, so that only string data is taken from it.

Please send your replies as soon as possible.

Thanks in Advance.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look around in the API documentation of the classes String and Character.

If you have a string and you want to remove all the digits from it, you could write a loop to go over all the characters in the string. You can use Character.isDigit(...) to see if a character is a digit or not. In the loop, append the characters to a StringBuilder (or StringBuffer) and skip over the characters that are digits.

Please try to write this code yourself - and if you have difficulties, show us what you wrote and tell us why it doesn't yet work as you want it.
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could also use a regular expression to get the same result with code that is easier to read. If you get adventerous and want to try regular expressions, this tutorial is a good place to start.

Regardless of how you try to tackle the problem, you should post back with any difficulties you encounter and include what you've tried and what points you're stuck on.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!