vb.net 查找字符串中子字符串第一次出现的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/932073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find position of first occurrence of a substring in a string
提问by Marcus Tik
I wan't a method with which to find a string within another string. It should return the position of the first occurrence of the substring. (In VB 2008 !)
我不需要在另一个字符串中查找字符串的方法。它应该返回子字符串第一次出现的位置。(在 VB 2008 中!)
回答by Matthew Flaschen
回答by Daniel Wedlund
I think you are looking for InStr function, see: InStr at msdn
我认为您正在寻找 InStr 函数,请参阅:msdn 上的 InStr
回答by Dale E. Moore
position = instr([stringField] & " ", " ")
position = instr([stringField] & " ", " ")
Looking for the first blank in what might be an empty string named [stringField]. The ' & " "' avoids an error situation where there are no blanks in [stringField].
在可能是名为 [stringField] 的空字符串中寻找第一个空格。' & " "' 避免了 [stringField] 中没有空格的错误情况。