• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to know the string is number or charactor?

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to know the string is number or charactor?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically, a String is an object representing a sequence of characters. One way to access particular characters within a String is by calling String's charAt(int index) method. Once you have that char, you can test whether it's a digit or a letter by calling Character.isDigit(char c) or Character.isLetter(char c).
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depending on your requirements a regular expression might be useful.



That's a simple example where b will be true if the entire String myString is composed of digits.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The String class actually provides a shortcut method for this...



Henry
 
lijun wang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to use this:
boolean b = myString.matches("\\d+");
but has the error in RAD:
The method matches(String) is undefined for the type String

WHY? I checked java API, string has this method!
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lijun wang:

WHY? I checked java API, string has this method!



The regular expression engine was added to Java 1.4... What version of Java are you using?

Henry
 
lijun wang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use RAD 6.0.1, is its java version 1.3, I can't believe, how to check the java version of RAD?
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by lijun wang:
I use RAD 6.0.1, is its java version 1.3, I can't believe, how to check the java version of RAD?



You can Check the version very easily.

Follow the following procedure.

-----------------------------

1) Select WINDOW --> Preferences in RAD.

2) in the Left panle expand JAVA

3) Select Installed JREs

4) Then It will show you the JRE it is using,,

5) if it is 1.3 then change it to point to the installed 1.4 or higger.

But

RAD 6.* comes with JRE 1.4 >.

Check your installation.

Thank you.

 
lijun wang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I install a jre5 and set it as RAD dfault jre, but I still can't import java.util.regex, and String has no matches method, why???
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic