Numeric Parse Method

<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
The Parse Method converts a string that represents a .NET Framework Numeric base type to an actual .NET Framework Numeric base type. It takes the following forms, where XXX is the name of the Numeric base data-type class:

public static XXX Parse(String s);
public static XXX Parse(String s, NumberStyles style);
public static XXX Parse(String s, NumberStyles style, NumberFormatInfo info);
The Parse Method takes a combination of three parameters: the string to be converted, one or more values from the NumberStyles enumeration , and a NumberFormatInfo class. All Numeric strings produced by the Parse Method, except hexadecimal strings, will always be parsable by this Method. Because the Parse Method assumes that all string input represents a base-10 value, no non base-10 values are parsable. It will also not Parse strings that represent the values NaN, PositiveInfinity, or NegativeInfinity of the Single and Double classes because they are not real numbers.

The following example converts a string to an int value, increments that value, and displays the result.

[C#]
string MyString = "12345";
int MyInt = int.Parse(MyString);
Myint++
Console.WriteLine(MyInt);
//Results in "12346"
The NumberStyles enumeration is usefull if you have a string that contains non-Numeric characters that you want converted into a .NET Framework Numeric base type. For example, a string that contains commas, parentheses, or currency symbols cannot be converted to an int value under the Parse Method if the NumberStyles enumeration is not used. The following code is invalid and will raise an exception with the message, "The input string wasn't in the correct format."

[C#]

string MyString = "123,456";
int MyInt = int.Parse(MyString);
Console.WriteLine(MyInt);
//Raises exception
When you apply the NumberStyles enumeration with the AllowThousands flag, the Parse Method will ignore the comma that raised the exception in the previous example. The following example uses the same string as the previous example, but does not raise an exception.

[C#]

string MyString = "123,456";
int MyInt = int.Parse(MyString, NumberStyles.AllowThousands);
Console.WriteLine(MyInt);
//Results in "123456&
11AJ10PN0542c.jpg
seover="window.status='正文--Numeric Parse Method';return true">
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 728x15, 创建于 08-4-23MSDN */ google_ad_slot = "3624277373"; google_ad_width = 728; google_ad_height = 15; //--> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"><!-- google_ad_client = "pub-2947489232296736"; /* 160x600, 创建于 08-4-23MSDN */ google_ad_slot = "4367022601"; google_ad_width = 160; google_ad_height = 600; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

numeric method

2015年04月17日 6.96MB 下载

C++ parse excel

2011年04月14日 5.58MB 下载

JSON2.JS JSON.JS JSON_PARSE.JS

2010年11月19日 21KB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭