• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String reverse

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I have a string looking like this "2001-12-12". I need to transform it to look like this "12-12-2001" How do i do this?
StringBuilder reverse() just give me "21-21-1002" but that is not what i need. Is there any way to do this, or i need to make my own method?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use String.split() to split on occurrence of '-', and you'll have the three separate pieces you need. Now put them back together in the order you want them.
 
Ranch Hand
Posts: 56
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ivan,

there is no direct way for this type of string conversion. You could to the following:
Convert your string into a Date and use SimpleDateFormat to get the string representation of this Date in the format you want.
See for instance http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html

BTW, if you have all the time your 2001-12-12 format it's easier to implement your own conversion method using the dashes as stop flags.

Regards,
Ramon
 
Ivan Kesic
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok ill convert it with dashes, thank you!
 
My, my, aren't you a big fella. Here, have a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic