当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET String.IndexOfAny方法代码示例

本文整理汇总了VB.NET中System.String.IndexOfAny方法的典型用法代码示例。如果您正苦于以下问题:VB.NET String.IndexOfAny方法的具体用法?VB.NET String.IndexOfAny怎么用?VB.NET String.IndexOfAny使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.String的用法示例。


在下文中一共展示了String.IndexOfAny方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: Example

Module Example
   Public Sub Main()
      Dim chars() As Char = { "a"c, "e"c, "i"c, "o"c, "u"c, "y"c, 
                              "A"c, "E"c, "I"c, "O"c, "U"c, "Y"c }
      Dim s As String = "The long and winding road..."
      Console.WriteLine("The first vowel in {2}   {0}{2}is found at position {1}", 
                        s, s.IndexOfAny(chars) + 1, vbCrLf)                         
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:9,代码来源:String.IndexOfAny

输出:

The first vowel in
The long and winding road...
is found at position 3

示例2: Sample

' Sample for String.IndexOfAny(Char[], Int32)
Class Sample
   Public Shared Sub Main()
      Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
      Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
      Dim str As String = "Now is the time for all good men to come to the aid of their party."
      Dim start As Integer
      Dim at As Integer
      Dim target As String = "is"
      Dim anyOf As Char() = target.ToCharArray()
      
      start = str.Length / 2
      Console.WriteLine()
      Console.WriteLine("Search for a character occurrence from position {0} to {1}.", _
                           start, str.Length - 1)
      Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
      Console.Write("A character in '{0}' occurs at position: ", target)
      at = str.IndexOfAny(anyOf, start)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.WriteLine()
   End Sub
End Class
'
'
'Search for a character occurrence from position 33 to 66.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'A character in 'is' occurs at position: 49
'
开发者ID:VB.NET开发者,项目名称:System,代码行数:35,代码来源:String.IndexOfAny

示例3: Sample

' Sample for String.IndexOfAny(Char[], Int32, Int32)
Class Sample
   Public Shared Sub Main()
      Dim br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
      Dim br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456"
      Dim str As String = "Now is the time for all good men to come to the aid of their party."
      Dim start As Integer
      Dim at As Integer
      Dim count As Integer
      Dim target As String = "aid"
      Dim anyOf As Char() = target.ToCharArray()
      
      start =(str.Length - 1) / 3
      count =(str.Length - 1) / 4
      Console.WriteLine()
      Console.WriteLine("The first character occurrence from position {0} for {1} characters.", start, count)
      Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str)
      Console.Write("A character in '{0}' occurs at position: ", target)
      
      at = str.IndexOfAny(anyOf, start, count)
      If at > - 1 Then
         Console.Write(at)
      Else
         Console.Write("(not found)")
      End If
      Console.WriteLine()
   End Sub
End Class
'
'The first character occurrence from position 22 for 16 characters.
'0----+----1----+----2----+----3----+----4----+----5----+----6----+-
'0123456789012345678901234567890123456789012345678901234567890123456
'Now is the time for all good men to come to the aid of their party.
'
'A character in 'aid' occurs at position: 27
'
开发者ID:VB.NET开发者,项目名称:System,代码行数:36,代码来源:String.IndexOfAny

示例4: String.IndexOfAny(String sub)

' 导入命名空间
Imports System

Public Class MainClass

   Shared Sub Main()
      Dim letters As String = "abcdefghijklmabcdefghijklm"
      Dim searchLetters As Char() = New Char() {"c"c, "a"c, "$"c}

      Console.WriteLine("IndexOfAny to find first occurrence of character in array")
      Console.WriteLine("First occurrence of ""c""," & _
        " ""a"" or ""$"" is located at " & _
        letters.IndexOfAny(searchLetters))

      Console.WriteLine("First occurrence of ""c"", ""a"" or " & _
         """$"" is located at " & _
         letters.IndexOfAny(searchLetters, 7))

      Console.WriteLine("First occurrence of ""c"", ""a"" or " & _
         """$"" is located at " & _
         letters.IndexOfAny(searchLetters, 20, 5))

   End Sub ' Main

End Class
开发者ID:VB程序员,项目名称:System,代码行数:25,代码来源:String.IndexOfAny


注:本文中的System.String.IndexOfAny方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。