How to compare / filter a string?

I've been looking for a way to filter out numbers in a string like this:

String tmp[] ={"1'","2'","3'","4'","5'","6'","7'","8'","9'","0"};

if (string2.contains(tmp){

///doSomething

}

but the contains method returns a boolean and what i want is that it looks for the entire string if it contains 1,2,3, etc..

I suppose i could use reged but i'm not very familiar with that.

[845 byte] By [deAppela] at [2007-11-27 9:11:05]
# 1

I'm kind of confused here. String.contains(s) only works if s is a CharSequence which can be a String, StringBuffer, StringBuilder, or CharBuffer. But you are using it with an array of strings....

Perhaps if you told us what the underlying goal here is. What do you want to do with this information? What do you mean by "filter out numbers"?

petes1234a at 2007-7-12 21:56:19 > top of Java-index,Java Essentials,Java Programming...
# 2

> I'm kind of confused here. String.contains(s) only

> works if s is a CharSequence which can be a String,

> StringBuffer, StringBuilder, or CharBuffer. But you

> are using it with an array of strings....

>

> Perhaps if you told us what the underlying goal here

> is. What do you want to do with this information?

> What do you mean by "filter out numbers"?

im using jdeveloper to develop an application with jsp/jspx frontend and on one of my forms i want to filter out numbers in a string so that a user can't enter any numbers.

I kinda knew that the x.contains(); method didn't work with the string array but i don't know any method that would let me compare several values.

Message was edited by:

deAppel

deAppela at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 3
Either experiment with regex, or do it for instance by iterating over the string, using the Character.isDigit method on each until it returns true or you've exhausted the iteration.Don't tell me you need 'teh codez' for this.
warnerjaa at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 4

> Either experiment with regex, or do it for instance

> by iterating over the string, using the

> Character.isDigit method on each until it returns

> true or you've exhausted the iteration.

>

> Don't tell me you need 'teh codez' for this.

Not really, im confident in my coding skills. I just want to know what methods I can use best. I haven't done any regex's but i'll take a look on that and see how it can be done.

if all fails i can code it the "nasty" way, it will work but its not the best way to do it.

deAppela at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 5

The other thing I was / am confused about is that each element in the array was a number and an apostrophy. i.e.: 5'

What's the apostrophy for?

Also, regex may look slicker, but it's not always the quickest way (as in cpu cycles). Sometimes "nasty" is better.

Message was edited by:

petes1234

petes1234a at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 6
My bad :) the ' shouldn't be there, made a bad typo. its "1" , "2" etc.
deAppela at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 7

Well, thanks for answering my question.

I'm currently reading this: http://java.sun.com/docs/books/tutorial/essential/regex/intro.html

My "nasty" code works and tested it just a min ago but i'll see if i can change the code and use regex instead because it will shorten my code significantly.

deAppela at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...
# 8
can we see the "nasty" version?
petes1234a at 2007-7-12 21:56:20 > top of Java-index,Java Essentials,Java Programming...