Results 1 to 4 of 4
- 02-20-2011, 12:39 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
short month = Short.parseShort(splitarray[2].toString()));
Hello,
I am parsing a string and need to store the value as a short.
Using the following line of code:
short month = Short.parseShort(splitarray[2].toString()));
Although its returning 2 instead of 02.
How to preserve the actual value of 02?
I've reversed engineered a schema, that is not controlled by me. As a result the value will need to be stored as a short instead of string.
Thanks, AC.
- 02-20-2011, 12:46 AM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Well, since 2 == 02 == 002 == 0002 I don't see where the problem is? If you just want the 02 at output you could simply do this:
This will append the 0 to months 1-9 and keep months 10-12 as they are.Java Code:Short s = someMethod(); //notice the upper case String a = s.toString(); if(a.length() == 1) a = "0"+a;
Ever seen a dog chase its tail? Now that's an infinite loop.
- 02-20-2011, 11:41 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Yeah I could do that if I could store the value as a string.
The schema requires a short value. I'm generating an XML file using CastorXML and have reversed engineered the objects based on a schema that I have no control over.
- 02-20-2011, 12:15 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,406
- Blog Entries
- 7
- Rep Power
- 17
As m00nchile already wrote: ints don't have leading zeros. If you want to display one with those leading zeros you have to convert it to a String and prepend those leading zeros; M00nchile already gave you a solution. You don't have to store anything as a String type, you just have to convert your short to a String, fiddle a bit with it and display it.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
two short codes
By Libertyman in forum New To JavaReplies: 7Last Post: 06-21-2010, 03:22 PM -
Need help with short problem
By fataguila in forum New To JavaReplies: 1Last Post: 01-30-2010, 08:58 AM -
Short Circuiting?
By Philly0494 in forum New To JavaReplies: 12Last Post: 11-12-2009, 10:45 AM -
Short-cut key
By tskumarme in forum New To JavaReplies: 2Last Post: 05-28-2008, 04:16 PM -
Short/Integer
By mew in forum New To JavaReplies: 3Last Post: 12-06-2007, 09:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks