本文整理汇总了VB.NET中System.String.Contains方法的典型用法代码示例。如果您正苦于以下问题:VB.NET String.Contains方法的具体用法?VB.NET String.Contains怎么用?VB.NET String.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String 的用法示例。
在下文中一共展示了String.Contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Example
Class Example
Public Shared Sub Main()
Dim s1 As String = "The quick brown fox jumps over the lazy dog"
Dim s2 As String = "fox"
Dim b As Boolean = s1.Contains(s2)
Console.WriteLine("'{0}' is in the string '{1}': {2}",
s2, s1, b)
If b Then
Dim index As Integer = s1.IndexOf(s2)
If index >= 0 Then
Console.WriteLine("'{0} begins at character position {1}",
s2, index + 1)
End If
End If
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:String.Contains 输出:
fox' is in the string 'The quick brown fox jumps over the lazy dog': True
fox begins at character position 17
示例2: StringExtensions
' 导入命名空间
Imports System.Runtime.CompilerServices
Module StringExtensions
<Extension()>
Public Function Contains(str As String, substring As String,
comp As StringComparison) As Boolean
If substring Is Nothing Then
Throw New ArgumentNullException("substring",
"substring cannot be null.")
Else If Not [Enum].IsDefined(GetType(StringComparison), comp)
Throw New ArgumentException("comp is not a member of StringComparison",
"comp")
End If
Return str.IndexOf(substring, comp) >= 0
End Function
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:17,代码来源:String.Contains
示例3: Example
Public Module Example
Public Sub Main
Dim s As String = "This is a string."
Dim sub1 As String = "this"
Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1)
Dim comp As StringComparison = StringComparison.Ordinal
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp))
comp = StringComparison.OrdinalIgnoreCase
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp))
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:String.Contains 输出:
Does 'This is a string.' contain 'this'?
Ordinal: False
OrdinalIgnoreCase: True
注:本文中的System.String.Contains方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论