本文整理匯總了VB.NET中System.String.LastIndexOfAny方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET String.LastIndexOfAny方法的具體用法?VB.NET String.LastIndexOfAny怎麽用?VB.NET String.LastIndexOfAny使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.String
的用法示例。
在下文中一共展示了String.LastIndexOfAny方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Sample
' Sample for String.LastIndexOfAny(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 - 1) / 2
Console.WriteLine("The last character occurrence from position {0} to 0.", start)
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.LastIndexOfAny(anyOf, start)
If at > - 1 Then
Console.Write(at)
Else
Console.Write("(not found)")
End If
Console.Write("{0}{0}{0}", Environment.NewLine)
End Sub
End Class
輸出:
The last character occurrence from position 33 to 0. 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: 12
示例2: Sample
' Sample for String.LastIndexOfAny(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) * 2 / 3
count =(str.Length - 1) / 3
Console.WriteLine("The last 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.LastIndexOfAny(anyOf, start, count)
If at > - 1 Then
Console.Write(at)
Else
Console.Write("(not found)")
End If
Console.Write("{0}{0}{0}", Environment.NewLine)
End Sub
End Class
輸出:
The last character occurrence from position 44 for 22 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
示例3: Sample
' Sample for String.LastIndexOfAny(Char[])
_
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 - 1
Console.WriteLine("The last character occurrence from position {0} to 0.", start)
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.LastIndexOfAny(anyOf)
If at > - 1 Then
Console.Write(at)
Else
Console.Write("(not found)")
End If
Console.Write("{0}{0}{0}", Environment.NewLine)
End Sub
End Class
輸出:
The last character occurrence from position 66 to 0. 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: 58