[program-java] Re: String to int...

  • From: "Sina Bahram" <sbahram@xxxxxxxxx>
  • To: <program-java@xxxxxxxxxxxxx>, <program-l@xxxxxxxxxxxxx>
  • Date: Thu, 24 Sep 2009 09:10:04 -0400

Quick and dirty solution is to step  through the string, one char at a time,
until you reach a character which is not 0.  this might happen on the first
char or the third, whatever. Anyways, then use that index to do a substring,
then pass that substring into Integer.parseInt

This can be done in one line, essentially.

Take care,
Sina


________________________________

From: program-java-bounce@xxxxxxxxxxxxx
[mailto:program-java-bounce@xxxxxxxxxxxxx] On Behalf Of Corbett, James
Sent: Thursday, September 24, 2009 9:06 AM
To: program-l@xxxxxxxxxxxxx; program-java@xxxxxxxxxxxxx
Subject: [program-java] String to int...



Sorry for the cross posting?. I have a COBOL copybook that defines an
element as Pic 9(5)? 

In my Java class I need to pass into my setter an integer for obvious
reasons. COBOL under the hood needs me to pass 00000 if the field is empty
because I'm actually building the com area at this point. If however the
field contains 999 I must still pass 00999 to fulfil the expected length?.

Ok, I have a string "00999" and need to convert it to an integer?. If I do
so, then the leading zeros are stripped off and my com area is 2 bytes
short?. Don't ask why or how it's the way it is?.

So, how do I manage this? 

Jim 

James M. Corbett 

Programmer / Analyst 
GST/HST Micros | Micros de la TPS/TVH 
Business Suite Assessing Systems (BSAS) 
Revenue and Accounting Systems Directorate (RASD) | Direction des Systèmes
de revenu et de comptabilité (DSRC) 
Information Technology Branch (ITB) | Direction générale de l'informatique
(DGI) 
Canada Revenue Agency | Agence du revenue du Canada 

(613) 941-1338 

"...Is a hippopotamus a hippopotamus, or just a really cool Opotamus?" 



Other related posts: