• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent Please

 
Rajesh Kumar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
please check this
in my program
String format = 19971230;
i want to display this string like in the following format
1997-12-30
How can i add "-" after 4 characters and another "-" after 2 characters using if conditions...
please help me..
this is urgent
thanksinadvance
yours
rajesh
 
Matthew Margolis
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can just create a new string using the parts of that string seperated by a -
read the first 4 then insert - then read two insert - read two insert -
 
Kaspar Dahlqvist
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tjipp!
Maybe this can help you...
StringBuffer sb = new StringBuffer("" + 20011119);
sb.insert(4, '-');
sb.insert(7, '-');
System.out.println(sb.toString());

//Kaspar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic