• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to know the string is number or charactor?

 
lijun wang
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to know the string is number or charactor?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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).
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic