问题描述
在VB 6中,我曾经做过以下几样的事情:
如果离开(str,3)=" abc"然后
在VB.NET中,当我执行以下操作
sStr.Substring(0,3),并且sStr少于3个字符时,它将给
我一个错误。
例如:sStr =" a",如果我做sStr.Substring(0,3),它会给出我错了。
所以,如果len(sStr)> = 3则我被迫做
然后
如果sStr.Substring(0,3)
:
除上述代码之外,还有更简单的方法吗?
谢谢
请注意,这不是100%等价物:
\\\
MsgBox(" Foo" .StartsWith(ChrW( & HFEFF)&Foo)
///
将在''de-DE''上返回''True''例如,在.NET 2.0中使用''en-US''系统。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
In VB 6 I used to do like the following:
if left(str,3) = "abc" then
In VB.NET when I do the following
sStr.Substring(0, 3), and the sStr has fewer than 3 characters, it will give
me an error.
For ex: sStr = "a", if I do sStr.Substring(0, 3), it will give me an error.
So, I was forced to do
if len(sStr) >= 3 then
if sStr.Substring(0, 3)
:
Is there an easier way to to it besides the above code ?
Thanks
Note that is is not 100 % equivalent:
\\\
MsgBox("Foo".StartsWith(ChrW(&HFEFF) & "Foo")
///
will return ''True'' on a ''de-DE'' and ''en-US'' system in .NET 2.0, for example.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
这篇关于子串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!