View Single Post
Old 10-04-2007, 10:37 AM   #43 (permalink)
Murr
Token Gnome
 
Murr's Avatar
 
Join Date: Jan 2002
Location: Chapel Hill, NC
Posts: 1,817
+11 Internets
Send a message via AIM to Murr
Doesn't java have string.split? This might not compile but a general flow and alternative to hardcoded substring ops.:
Code:
String inDate, outDate; String[] dateSplit; // holds split string inDate = keyboard.nextString(); dateSplit = inDate.split("/"); // splits the string on "/" character outDate = dateSplit[1] + "-" + dateSplit[0] + "-" + dateSplit[2]; System.out.println(outDate);
Split divides a string up into segments based on the character you "split" on and puts them into an array, so if you pass it
"09/11/2001" and split on "/" you get an array with elements
[09,11,2001]
So when I say dateSplit=inDate.split("/")
dateSplit[0]="09", dateSplit[1]="11", and dateSplit[2]="2001"
Now you can just recombine the separate strings as shown and you get
11-09-2001
Murr is offline   Reply With Quote

 
Uberguilds Network