Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP ME PLEASE!!!!

Status
Not open for further replies.

NevG

Programmer
Oct 10, 2000
162
GB
How can I cast a char[] into an int?

Do I have to through some tedious routine of casting it to something else first ?

Somebody please help me !!

Thanks [sig][/sig]
 
what do you mean by char[]? is it an array or a string?
if array and you want each element in the array to be a integer then something like
-some of these round brackets should be square but i need them for the code font
[tt]
for(int i = 0; i < charArray.length; i ++){
[tab]intArray(i) = (int)charArray(i);
}
[/tt]
if you want the whole thing as one number first make them into a string
[tt]
String s = &quot;&quot;;
for(int i = 0; i < charArray.length; i ++){
[tab]s+=charArray(i);
}
[/tt]
then use
[tt]
int i = Integer.parseInt(s);
[/tt]
hopr that helps X-) [sig]<p>Chris Packham<br><a href=mailto:kriz@i4free.co.nz>kriz@i4free.co.nz</a><br><a href= > </a><br>A thousand mokeys at a thousand machines, it happened, it got called the internet.[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top