• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to remove Numeric values from a String

 
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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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.
 
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!