aspose file tools*
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
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
Author

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
Greenhorn

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

"[-]?[0-9]*.[0-9]+u"
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: http://aspose.com/file-tools
 
subject: SMART way to match [0.997u -9.978u .98u -.987u ]