indexof和instr之间的差异 [英] differences between indexof and instr

查看:145
本文介绍了indexof和instr之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道IndexOf和InStr有什么区别吗?
您能给我一个示例如何使用它吗?

Does anyone know what''s the difference between IndexOf and InStr?
And can u give me an example how to use it?

推荐答案

请看一下MSDN站点:InStr [ IndexOf [
Have a look at MSDN site: InStr[^], IndexOf[^]


在这种情况下,能够搜索并阅读您发现的内容肯定会有所帮助:

String.IndexOf [ InStr() [
Being able to google and reading what you find surely helps in this case:

String.IndexOf[^]

InStr()[^]

So the former is an instance method of the class string and the latter is a Visual Basic runtime member (aka built in) function where the arguments may be nothing. IndexOf always needs an string instance to operate on.

Regards,

Manfred


从这里可以看到 http://msdn.microsoft.com/en-us/library/8460tsh1(v = vs.90).aspx [ http://msdn.microsoft.com/en-us/library/k8b1470s. aspx [ ^ ] ,IndexOf 是.NET Framework的 an instance method of string类,可以在in VB and C#. start index is 0 based中使用,并在找不到字符串的情况下返回 -1 .

在上面的参考文献中给出了使用上述功能的示例.

我认为IndexOf 方法很好用,因为它是所有.NET语言所通用的.
As can be seen from here http://msdn.microsoft.com/en-us/library/8460tsh1(v=vs.90).aspx[^], InStr is a VisualBasic specific Shared function, which returns the first occurance of one string in another string. The start index is 1 based. It returns 0 in case of non finding the string.

As can be seen from here http://msdn.microsoft.com/en-us/library/k8b1470s.aspx[^] the, IndexOf is an instance method of string class of .NET framework and can be used in VB and C#. The start index is 0 based and returns -1 in case of non finding the string.

The examples for usage of the above functions are given at the above references.

I think the IndexOf method is good to use as it is common for all .NET languages.


这篇关于indexof和instr之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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