|
-
Nov 17th, 2003, 08:44 PM
#1
Thread Starter
Junior Member
Converting a string to int and back
Hey,
I am having some difficulties converting a string which contains numbers into an integer and then dividing the number by 15 then converting the result back to a string.
I'm pretty sure I am way off and stuff but this is what I got:
Code:
Nums[intX]=(string)Convert.ChangeType((int)Convert.ChangeType(Nums[intX], typeof(int))/15, typeof(string));
The error that I am getting is: System.FormatException: Input string was not in a correct format.
I'm probably not using the ChangeType method properly so any help is greatly appriciated.
-
Nov 17th, 2003, 09:59 PM
#2
PowerPoster
Try that:
Nums[intX] = (int)(int.Parse(Nums[intX])/15).toString()
I haven't verified it works, so if it doesn't, look into the parse() method of the integer object. It will parse a string into a integer.
-
Nov 18th, 2003, 06:04 PM
#3
Thread Starter
Junior Member
Same error, I did change it so it dumps the result into an integer array so it doesn't need to convert it back to a string.
This is my new code:
ActualNums[intX] = (int)(int.Parse(Nums[intX])/15);
and I still get: System.FormatException: Input string was not in a correct format.
And I checked and the Nums[] array is a string; however when I try this:
ActualNums[intX] = (int)(int.Parse("555")/15);
It works...
TIA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|