HOW TO:在 Visual C++ .NET 中从 System::String* 转换为 Char*
2010-08-05 10:35
387 查看
本文介绍使用 Visual C++ .NET 中的托管扩展从 System::String* 转换为 char* 的若干方法。
代码
public void ConvertStringFloat(string stringVal) {
float floatVal = 0;
try {
floatVal = System.Convert.ToSingle(stringVal);
System.Console.WriteLine(
"The string as a float is {0}.", floatVal);
}
catch (System.OverflowException){
System.Console.WriteLine(
"The conversion from string-to-float overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string is not formatted as a float.");
}
catch (System.ArgumentNullException) {
System.Console.WriteLine(
"The string is null.");
}
// Float to string conversion will not overflow.
stringVal = System.Convert.ToString(floatVal);
System.Console.WriteLine(
"The float as a string is {0}.", stringVal);
}
代码
public void ConvertStringFloat(string stringVal) {
float floatVal = 0;
try {
floatVal = System.Convert.ToSingle(stringVal);
System.Console.WriteLine(
"The string as a float is {0}.", floatVal);
}
catch (System.OverflowException){
System.Console.WriteLine(
"The conversion from string-to-float overflowed.");
}
catch (System.FormatException) {
System.Console.WriteLine(
"The string is not formatted as a float.");
}
catch (System.ArgumentNullException) {
System.Console.WriteLine(
"The string is null.");
}
// Float to string conversion will not overflow.
stringVal = System.Convert.ToString(floatVal);
System.Console.WriteLine(
"The float as a string is {0}.", stringVal);
}
相关文章推荐
- HOW TO:在 Visual C++ .NET 中从 System::String* 转换为 Char*
- HOW TO:在 Visual C++ .NET 中从 System::String* 转换为 Char*
- 在 Visual C++ .NET 中从 System::String* 转换为 Char* 或者 CString
- Visual C++ .NET 中从 System::String* 转换为 Char*
- 如何在在Visual C++ .NET 中將System::String* 转换为 Char*
- 在 Visual C++ .NET 中从 System::String* 转换为 Char*
- Visual C++ .NET 中 System::String^ 和 char * 互转
- 在C++.NET中,System::String^与char*相互转换
- Visual C++ .NET 中 System::String^ 和 char * 互转
- Visual C++.NET中的字符串转换方法
- System::String *,char*,string 等的类型转换
- c++中string、const char*和char*之间的相互转换
- c++中的一些类型转换 : CString,string,int ,long,double,char*,const char*,date等
- C#下System::String转换成C++下string
- C++ 数字、string和char*的转换
- HOW TO:在 Visual C# .NET 中使用 System.Xml 合并两个 XML 文档中的数据
- 在VC++.net中将System::String __gc* 转换为本机的char *或wchar_t *的三种方法
- Oracle用sys_Guid()创建为视图ID,.net跨库保存的值却为system_Byte[]问题解决--将sys_Guid()转换为string
- Visual C++.NET字符串转换
- c++中的一些类型转换 : CString,string,int ,long,double,char*,const char*,date等 .