java - Split zero in String -
guys have int
value parse string []
, should write:
if (first element == 0) split return value without 0 @ start.
for example have 01, 02, 03, 04, 05, 06, 07, 08, 09, 10,... 20... 30..
so in return in split 0
value 0
first element, , return me next:
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,... 20... 30..
actually need calendar, i've take date return me days 01, 02, 03
, on. here method code:
public string setcurrentcalendarday() throws testexception, parseexception{ if (!getpage().getsession().canrun()) throw new testexception(page.invalidstatemessage); string currentdate = ""; date date = new date(); calendar cal = calendar.getinstance(); cal.settime(date); simpledateformat formatter = new simpledateformat("dd"); currentdate = formatter.format(date); return currentdate; }
the first option use new simpledateformat("d")
, not ("dd")
have 1 digit minimum , not two.
the second option use regex 1 return currentdate.replacefirst("^0+(?!$)", "")
replace first 0
nothing.
Comments
Post a Comment