File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes storing strings in a specific format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "storing strings in a specific format" Watch "storing strings in a specific format" New topic
Author

storing strings in a specific format

Ben Tigger
Greenhorn

Joined: May 26, 2004
Posts: 7
hi,

I'm wondering if u could give me any ideas as to how i would go about storing a String in the following format:

Letter Letter space Number Number space Letter Letter Letter

its for storing car registration numbers

Cheers
[ May 27, 2004: Message edited by: Ben Tigger ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What do you mean by "storing"?

Are you rather asking about how to verify the format of a String? If that is the case, then a regular expression would certainly fit the bill well. If you'd like more information on how to use regular expressions in Java, just ask.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Ben Tigger
Greenhorn

Joined: May 26, 2004
Posts: 7
what i mean is that the user enters the registration number and it is stored as a variable in that format. or is there any way to make sure that the user enters it in that format
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
How does the user enter the value? Is it a text field on a form in a web page? Is it through a JOptionPane, or a frame-based application? Is it through the command prompt?

No matter the input mechanism, you can certainly format the input (which is harder depending on how many different user-input patterns you want to be able to handle), as well as verify that the input format is correct, and then prompt the user to input the value again if the format is wrong (which is much easier than the previous option).

To verify the pattern of the input data, you could make use of a few of the methods in the String class and the Character class to be able to analyze the overall length, as well as the type of each character individually.

A less tedious solution to verify the patter of the input data would be to make use of regular expressions. For what I hope is an easy introduction to that subject, take a look at the two articles I wrote for the JavaRanch Journal. (Search for "regex" on that page.)
[ May 27, 2004: Message edited by: Dirk Schreckmann ]
 
GeeCON Prague 2014
 
subject: storing strings in a specific format