String to int

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2008
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: String to int

 
0
  #11
Feb 27th, 2008
Originally Posted by Ezzaral View Post
97 is the byte value of 'a'. Your read() call just got a single byte and converted it to int.

In any case, it's irrelevant. Without a stated encoding expectation, "asu" cannot be converted to int. Integer.parseInt() will convert a valid integer string to an int value. If you want to convert some other string to an int, there are many different ways to do so, but they are specific encoding methods - not just a general api call or statement.
even if you write Integer.parsrInt("asu"); you will get Number format exception but if you write Integer.parseInt("197") it will give the number 197.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: String to int

 
0
  #12
Feb 27th, 2008
Originally Posted by Parsu7 View Post
even if you write Integer.parsrInt("asu"); you will get Number format exception but if you write Integer.parseInt("197") it will give the number 197.
Of course, which is already mentioned. You are missing the entire point.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: String to int

 
0
  #13
Feb 27th, 2008
Originally Posted by Ezzaral View Post
Of course, which is already mentioned. You are missing the entire point.
I would be really gratefull to you if you could tell me the point which i am missing.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: String to int

 
0
  #14
Feb 27th, 2008
Integer.parseInt() was already explained. The real point is that there is no generic method to make "asu" an int. It is totally dependent upon how you need to encode the string and that is totally dependent on what you intend to use it for.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 28
Reputation: Parsu7 is an unknown quantity at this point 
Solved Threads: 1
Parsu7 Parsu7 is offline Offline
Light Poster

Re: String to int

 
0
  #15
Feb 27th, 2008
Originally Posted by Ezzaral View Post
Integer.parseInt() was already explained. The real point is that there is no generic method to make "asu" an int. It is totally dependent upon how you need to encode the string and that is totally dependent on what you intend to use it for.
Thanks, but can we write this to convert a string such as "asu" to integer

int x = br.read();
int y=br.read();
int z=br.read();

System.out.println(x+y+z);

Please do reply me.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,492
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 519
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: String to int

 
0
  #16
Feb 27th, 2008
You could, but what would the point be?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,688
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 227
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: String to int

 
0
  #17
Feb 27th, 2008
You can write whatever you want if this is the way you want to convert "asu" to a String. As it was said in the first reply what do you want to convert "asu" to?
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC