string to int
-
Using atoi will work: CString str = "42"; int i = atoi(str); Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
OOOPS!!!!! I've been in the MFC forum all day and my head is still in that :) Use the Convert static functions to do what you want.
string s = "42";
int i = Convert.ToInt32(s);Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
OOOPS!!!!! I've been in the MFC forum all day and my head is still in that :) Use the Convert static functions to do what you want.
string s = "42";
int i = Convert.ToInt32(s);Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
Parse is specific to the Int32 class while Convert is a generic class supporting all types. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
It should also be noted that in the case of converting a string to an int via the Convert class it calls Int32.Parse. James Simplicity Rules!
-
It should also be noted that in the case of converting a string to an int via the Convert class it calls Int32.Parse. James Simplicity Rules!
Good point, James. I'm so accustomed to using the Convert class for everything that I never think about Parse. Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
Using atoi will work: CString str = "42"; int i = atoi(str); Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
You might even be able to do this through PInvoke, but I wouldn't necessarily recommend it :) I think I'll stick with "What is Convert?", Alex :laugh: Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
OOOPS!!!!! I've been in the MFC forum all day and my head is still in that :) Use the Convert static functions to do what you want.
string s = "42";
int i = Convert.ToInt32(s);Cheers, Tom Archer Author, Inside C# A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
-
thx... i was looking for this conversion in string class. As I can see there is special class to conversions.
-
So I guess my followup question would be when to use one or the other (parse vs. convert). Also, is parse more efficient? Just looking for some guidelines here.
Convert can convert from all intrinsic datatypes to the other types; parse only accepts strings. Convert also calls the appropriate parse method when converting a string to that format except when converting UInt32 which isn't CTS compliant and converting string to string where it just returns the value ;P. I would use Convert for consistancy in code, but in some cases, Parse will take a few extra parameters you may wish to use. HTH, James Simplicity Rules!