使用CType或Integer.Parse将字符串解析为整数 [英] Use CType or Integer.Parse to parse a string into an integer

查看:84
本文介绍了使用CType或Integer.Parse将字符串解析为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我是否应该使用Integer.Parse将字符串转换为.NET中的整数

now?

CType(sUserID,Integer)或Integer.Parse( sUserID)


2)在.NET中使用字符串类修剪,获取长度等更好吗?

s1.trim或trim( s1)

s1.length或len(s1)


谢谢!

1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)

2) And is it better to use the string class to trim, get length, etc in .NET?
s1.trim OR trim(s1)
s1.length OR len(s1)

Thank you!

推荐答案

为什么要说避免VB兼容性库?是否有技术原因或仅仅是一个哲学原因?


克里斯


PS。 CType(String,Integer)等效于C#

" W.G中的(int)字符串。 Ryan eMVP <无线********* @ gmail.com>在消息中写道

新闻:Oi ************** @ TK2MSFTNGP11.phx.gbl ...
Why do you say to avoid the VB compatibility library? Is there a technical
reason or just a philosophical reason?

Chris

PS. CType(String, Integer) is equivalent to (int)String in C#
"W.G. Ryan eMVP" <Wi*********@gmail.com> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl...
1)'''在C#中没有CType所以在gp上 - 我会用Parse运行 - 除非你确定你永远不会在这两种语言之间切换
2)使用字符串类 - 避免VB兼容库尽可能多。

-
WG Ryan,MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Teresa <碲**** @ discussions.microsoft.com>在消息中写道
新闻:42 ********************************** @ microsof t.com。 ..
1) There''s no CType in C# so on gp - I''d run with Parse - unless you are
sure you''re never going to switch between the two languages
2) use the string class- avoid the VB compatibility library as much as
possible.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Teresa" <Te****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
1)我是否应该使用Integer.Parse将字符串转换为.NET中的整数
CType(sUserID,Integer)或Integer.Parse(sUserID) )

2)在
1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)

2) And is it better to use the string class to trim, get length, etc in


.NET中使用字符串类修剪,获取长度等更好吗?


.NET?

s1.trim或修剪(s1)
s1.length或len(s1)

谢谢!
s1.trim OR trim(s1)
s1.length OR len(s1)

Thank you!




1)C#中没有CType所以在gp上 - 我会用Parse运行 - 除非你是

确定你永远不会在两者之间切换语言

2)使用字符串类 - 尽可能避免VB兼容库




-

WG Ryan,MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com

" Teresa" <碲**** @ discussions.microsoft.com>在消息中写道

news:42 ********************************** @ microsof t.com ...
1) There''s no CType in C# so on gp - I''d run with Parse - unless you are
sure you''re never going to switch between the two languages
2) use the string class- avoid the VB compatibility library as much as
possible.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Teresa" <Te****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
1)我是否应该使用Integer.Parse将字符串转换为.NET中的整数
CType(sUserID,Integer)或整数.Parse(sUserID)

2)在
..NET中使用字符串类修剪,获取长度等更好吗? s1.trim或trim(s1)
s1.length或len(s1)

谢谢!
1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)

2) And is it better to use the string class to trim, get length, etc in ..NET? s1.trim OR trim(s1)
s1.length OR len(s1)

Thank you!



为什么要说避免VB兼容性库?是否有技术原因或仅仅是一个哲学原因?


克里斯


PS。 CType(String,Integer)等效于C#

" W.G中的(int)字符串。 Ryan eMVP <无线********* @ gmail.com>在消息中写道

新闻:Oi ************** @ TK2MSFTNGP11.phx.gbl ...
Why do you say to avoid the VB compatibility library? Is there a technical
reason or just a philosophical reason?

Chris

PS. CType(String, Integer) is equivalent to (int)String in C#
"W.G. Ryan eMVP" <Wi*********@gmail.com> wrote in message
news:Oi**************@TK2MSFTNGP11.phx.gbl...
1)'''在C#中没有CType所以在gp上 - 我会用Parse运行 - 除非你确定你永远不会在这两种语言之间切换
2)使用字符串类 - 避免VB兼容库尽可能多。

-
WG Ryan,MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Teresa <碲**** @ discussions.microsoft.com>在消息中写道
新闻:42 ********************************** @ microsof t.com。 ..
1) There''s no CType in C# so on gp - I''d run with Parse - unless you are
sure you''re never going to switch between the two languages
2) use the string class- avoid the VB compatibility library as much as
possible.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Teresa" <Te****@discussions.microsoft.com> wrote in message
news:42**********************************@microsof t.com...
1)我是否应该使用Integer.Parse将字符串转换为.NET中的整数
CType(sUserID,Integer)或Integer.Parse(sUserID) )

2)在
1) Should I use Integer.Parse to convert a string into an integer in .NET
now?
CType(sUserID, Integer) OR Integer.Parse(sUserID)

2) And is it better to use the string class to trim, get length, etc in


.NET中使用字符串类修剪,获取长度等更好吗?


.NET?

s1.trim或修剪(s1)
s1.length或len(s1)

谢谢!
s1.trim OR trim(s1)
s1.length OR len(s1)

Thank you!




这篇关于使用CType或Integer.Parse将字符串解析为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆