[.net] system:string to int

Started by
4 comments, last by Satan666 18 years, 8 months ago
I'm getting a input from a textbox, and what it'll be used for is as an integer, but I can't figure out how to convert it from a system::string __gc to and int. any ideas? [Edited by - Satan666 on July 26, 2005 4:37:15 AM]
Advertisement
Try System::Int32::Parse.

Or Convert::ToInt16

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development

These functions throw when the argument is badly formatted. This is probably fine in your case. But just so that you know, .NET 2.0 has an additionnal function System::Int32::TryParse that returns a bool indicating success/failure.
string s = "3213";int iNum = int.Parse(s);
Be sure to catch the following exceptions (taken directly from MSDN):
System.ArgumentNullException: s is null.
System.ArgumentException: style is not a valid combination of System.Globalization.Numberstyles enumerated constants.
System.FormatException: s is not in a format compliant with style.
System.OverflowException: s represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue.
Rob Loach [Website] [Projects] [Contact]
Much thanks, everything works fine :D:D

This topic is closed to new replies.

Advertisement