我怎么能使用不同的函数"InStr"这是我正在使用的代码并且工作正常但是离开InStr是我的目标
i = InStr(1, Hostname, Environment.Newline)
Run Code Online (Sandbox Code Playgroud)
Ňɏs*_*arp 20
String.Indexof() 有几个重载:
Dim jstr = "How much wood could a woodchuck chuck if a woodchuck..."
' Find a character from a starting point
ndx = jstr.IndexOf("w"c) ' == 2 (first w)
' or within a range:
ndx = jstr.IndexOf("o"c, 12) ' == 15 first o past 12 (cOuld)
'Find a string
ndx = jstr.IndexOf("wood") ' == 9
' ...from a starting point
ndx = jstr.IndexOf("wood", 10) ' == 22 (WOODchuck)
' ...or in part of the string
ndx = jstr.IndexOf("chuck", 9, 15) ' -1 (none in that range)
' using a specified comparison method:
ndx = jstr.IndexOf("WOOD", StringComparison.InvariantCultureIgnoreCase) ' 9
ndx = jstr.IndexOf("WOOD", nFirst, StringComparison)
ndx = jstr.IndexOf("WOOD", nFirst, nLast, StringComparison)
Run Code Online (Sandbox Code Playgroud)
还有一种String,LastIndexOf()方法可以在字符串中使用各种重载来获取最后一次出现的内容.
在您附近的VS 中的MSDN或对象浏览器(VIEW菜单|对象浏览器)中可用.
i = Hostname.Indexof(Environment.Newline, 1)
Run Code Online (Sandbox Code Playgroud)
如果你需要等效的C#代码,你可以使用汇编中的Strings类Microsoft.VisualBasic,因此代码可以如下:
using Microsoft.VisualBasic;
. . .
i = Strings.InStr(1, Hostname, Environment.NewLine);
Run Code Online (Sandbox Code Playgroud)

另一种方法是使用适当的String.Indexof功能.
链接:
| 归档时间: |
|
| 查看次数: |
42411 次 |
| 最近记录: |