Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

StringTokenizer

Status
Not open for further replies.

chripk

MIS
Feb 7, 2005
1
PH
How does this work? Can it be used to etract components of a date string? Is this the best/only approach?
 
A StringTokenizer parses up a String into Tokens using a delimiter(sp?). So if you had the string "Hello|okay|alright" and you wanted the | to be a delimiter then you'd create a StringTokenizer, the syntax would be:

String theString = new String("Hello|okay|alright");
StringTokenizer theTokenizer = new StringTokenizer(theString, "|");

If you give no delimiter, by default a space counts as a delimiter, you could parse a Date String using the default I would think. But I would also look at the GregorianCalendar Class if you're wanting to extract compotents of a Date.
 
So if my string containing a date "21/05/02", I would want the delimeter in this case to be "/". I want the user to input the date though? Then I want to convert the day, month and year into int values to display. What would the class for this look like?
 
Java has a class just for the purpose of parsing dates. It is java.text.SimpleDateFormat.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top