替代使用InStr [英] Alternative to using InStr

查看:51
本文介绍了替代使用InStr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用其他函数"InStr"这是我正在使用的代码,并且工作正常,但是远离InStr是我的目标

how can I use a different function "InStr" this is the code that I am using and works fine but moving away from InStr is my goal

i = InStr(1, Hostname, Environment.Newline)

推荐答案

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)

还有一个 String,LastIndexOf() 方法来获取字符串中某些内容的最后一次出现,并且还会产生各种重载.

There is also a String,LastIndexOf() method to get the last occurance of something in a string also with a variety of overloads.

MSDN 或对象浏览器中可用(查看菜单|对象浏览器)在您附近的VS中.

Available in MSDN or Object Browser (VIEW menu | Object Browser) in the VS near you.

i = Hostname.Indexof(Environment.Newline, 1)

这篇关于替代使用InStr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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