當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET String.Contains方法代碼示例

本文整理匯總了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;未經允許,請勿轉載。