File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes SMART way to match [0.997u -9.978u .98u -.987u ] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "SMART way to match [0.997u -9.978u .98u -.987u ]" Watch "SMART way to match [0.997u -9.978u .98u -.987u ]" New topic

SMART way to match [0.997u -9.978u .98u -.987u ]

Maha Hassan
Ranch Hand

Joined: Aug 02, 2005
Posts: 133
i have the following input ...[0.997u -9.978u .98u -.987u ]
do u have any SMART way to match it ..
the four cases in the list are the ONLY valid inputs
anyideas ??!!
fdafd fdafda

Joined: Aug 09, 2005
Posts: 6
I don't know if this is a SMART way of matching the number, but it should work. As the strings are relatively short, it won't matter much even if the pattern matching is inefficient

Alan Moore
Ranch Hand

Joined: May 06, 2004
Posts: 262
Do you mean only those four exact sequences are valid? If so, the easiest way to validate the input is with a simple comparison:
If those are just examples, how strictly does the input have to conform to them? Does there have to be zero or one digit before the decimal point, and two or three after?
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
Here is the recipe!
1.trim the string
2.remove the first and last character as they are [ and ]
3.use a string tokenizer with the space as a separator( I think it is the default)
4.For each token string
4.1 trim
4.2 Remove the last character because it is the letter u
4.3 parse double with Double class.
4.4 insert that double in a list or whatever you need

that's it!
I agree. Here's the link:
subject: SMART way to match [0.997u -9.978u .98u -.987u ]
It's not a secret anymore!