parse the string to get the integer value : String to Number « Data Type « Visual C++ .NET






parse the string to get the integer value

 
#include "stdafx.h"
using namespace System;

int main()
{
   String^ str1 = "115";
   String^ str2 = "1.4e-12";

   int i = Int32::Parse( str1 );


   double x = Double::Parse( str2 );

   // 
   int j = Convert::ToInt32( str1 );
   double y = Convert::ToDouble( str2 );

   try
   {
      int k = Int32::Parse("bad format");
   }
   catch(FormatException^ e)
   {
       Console::WriteLine("Exception occurred! {0}", e->Message );
   }
}

   
  








Related examples in the same category

1.Convert Strings to Numbers
2.Convert String to decimal