Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > comparing strings

Reply
Thread Tools

comparing strings

 
 
manzur
Guest
Posts: n/a
 
      03-07-2006
how do i know that the string which i have is in the my desired format
..

My format is zx
where z,x,y are integers.

thnx in advance

 
Reply With Quote
 
 
 
 
Bart Cremers
Guest
Posts: n/a
 
      03-07-2006
Use regular expressions.

Pattern patt = Pattern.compile("^\\d+:\\d+:\\d+$");
if (patt.matcher(input).matches()) {
// Yay!!!
} else {
// Boo
}

This code is not tested.

Regards,

Bart

 
Reply With Quote
 
 
 
 
hiwa
Guest
Posts: n/a
 
      03-07-2006
if (myString.matches("^\\d:\\d:\\d$")){
...
}

 
Reply With Quote
 
manzur
Guest
Posts: n/a
 
      03-07-2006

Greedy quantifiers
X? X, once or not at all
X* X, zero or more times
X+ X, one or more times
X{n} X, exactly n times
X{n,} X, at least n times
X{n,m} X, at least n but not more than m times

Reluctant quantifiers
X?? X, once or not at all
X*? X, zero or more times
X+? X, one or more times
X{n}? X, exactly n times
X{n,}? X, at least n times
X{n,m}? X, at least n but not more than m times

Possessive quantifiers
X?+ X, once or not at all
X*+ X, zero or more times
X++ X, one or more times
X{n}+ X, exactly n times
X{n,}+ X, at least n times
X{n,m}+ X, at least n but not more than m times

cn any one expalin me wht is the difference between the above three.
If some one can provide examples it would be great help
thnx in advance

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-07-2006
On 6 Mar 2006 23:34:32 -0800, "manzur" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>cn any one expalin me wht is the difference between the above three.


see http://mindprod.com/jgloss/regex.html

Sometime words fail. You need to write yourself a little test program
and feed it strings and see what it does.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
manzur
Guest
Posts: n/a
 
      03-07-2006
wht actually i want to know was :
In Greedy quantifiers the api says
X? X, once or not at all

In Reluctant quantifiers the api says

X?? X, once or not at all

I was not able to understand wht X means in the above two scenarious.

 
Reply With Quote
 
Jussi Piitulainen
Guest
Posts: n/a
 
      03-07-2006
manzur writes:

> wht actually i want to know was :
> In Greedy quantifiers the api says
> X? X, once or not at all
>
> In Reluctant quantifiers the api says
>
> X?? X, once or not at all
>
> I was not able to understand wht X means in the above two scenarious.


It stands for a regular expression. You can instantiate those
documentation lines with any old expression you want, as long as its
bound tight enough with respect to the quantifier.

[^_^]? matches [^_^] once or not at all
(<maybe>)? matches <maybe> once or not at all

X? stands for both of these, and many more.

<maybe>? matches <maybe and then > once or not at all

Here X? stands for >?.
 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      03-07-2006
Good read for regex novice:
http://java.sun.com/docs/books/tutor...gex/index.html
Differences Among Greedy, Reluctant, and Possessive Quantifiers
http://java.sun.com/docs/books/tutor...gex/quant.html

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      03-07-2006
On 6 Mar 2006 23:57:53 -0800, "manzur" <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>I was not able to understand wht X means in the above two scenarious.


Did you read the link I gave you?
Did you do write an experimenting regex class?
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
Comparing two strings HS1 Java 3 11-29-2004 04:21 PM
Which way is more efficient - comparing strings of different letter casing kaeli Java 8 11-18-2004 09:44 PM
Comparing C-Style Strings Curtis Gilchrist C++ 5 02-18-2004 07:31 PM
Comparing strings from within strings Rick C Programming 3 10-21-2003 09:10 AM



Advertisments