- 热门文章:
- · 日期和时间的转换
- · 自定义的转换格式
- · 如何将powerpoint转换为html
- · css设定表格宽度
- · .Net边学边讲(三)
- · Calling a Button Event from a Compiled DLL
- · datagrid怎么设置分页?
- · .NET之ASP Web Application快速入门(3)(转载)
- · .NET之ASP WebApplication快速入门(4)(转载)
- · .NET之ASP WebApplication快速入门(5)(转载)
- · .NET之ASP Web Application快速入门(1)(转载)
- · .NET之ASP Web Application快速入门(2) (转载)
上一篇:数值变换时的格式化字符举例 >>
Numeric Parse Method
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"
下一篇:日期和时间的转换 >>
相关文章:
- · ASP.NET中的错误处理支持
- · ASP.NET中的代码分离
- · 在ASP.NET中使用AdRotator控件(转)
- · 在ASP.NET中动态生成图形(转)
- · 用ASP.NET加密口令(转)
- · ASP.NET中的错误处理支持(转)
- · ASP.NET中发送Email完整实例(转)
- · ASP.NET中的注释符号
- · 老外编的程序(八):在CSharp里面使用Http Get方法
- · 显示当前浏览器头信息(HEADER)
- · 轮换广告
- · 一个dnslookuo例子。。。
- · beta2的web.config配置
- · 如何在web.config中建立公用的的数据库连接
- · asp.net key considerations(三)
- · asp.net key considerations(二)
- · WebPoll in C#[Vs.net Bate2 等级:中 高]
- · Form code generator V1.1 by Steve Schofield[bate2 等级:中级](转载:aspfree)
- · asp.net key considerations(一)从前用惯了asp的朋友看看这个吧,大家常问的如Request等问题解答得很清楚
- · 使用DataList进行3层编历
- · part1: ShowIssueCat.aspx.cs
- · part2: ShowIssueCat.aspx
- · DataNavigateUrlFormatString的使用方法
- · ASP.NET XML/XSL Transforms(转载www.aspalliance.com)
- · Hiding/Manipulating Databound Items(转载www.aspalliance.com)
- · 无刷新的聊天室的制作兼谈组件制作和ClientSide Script(一)
- · 关于异常捕获
- · 无刷新的聊天室的制作兼谈组件制作和ClientSide Script(二)
- · 转贴:用ASP.NET结合XML制作广告管理程序
- · 转贴:用ASP.NET结合XML制作广告管理程序(2)
- · ASP.NET: Dynamically set Text and Value fields for a DropDownList
- · asp.net优化(二)
- · DotNet中定制自己的表格
- · 回答讨饭猫之asp.net优化(一)
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--8
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--7
- · Common ASP.NET Code Techniques (DPC&DWC Reference)--9
- · 转转: ASP 内建对象Request和Respones
