Re: LastIndexOf in VB.NET
String.LastIndexOf Method
Reports the index position of the last occurrence of a specified Unicode character or String within this instance.
- LastIndexOf(Char): Reports the index position of the last occurrence of a specified Unicode character within this instance.
- LastIndexOf(String): Reports the index position of the last occurrence of a specified String within this instance.
- LastIndexOf(Char, Int32): Reports the index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position.
- LastIndexOf(String, Int32): Reports the index position of the last occurrence of a specified String within this instance. The search starts at a specified character position.
- LastIndexOf(String, StringComparison): Reports the index of the last occurrence of a specified string within the current String object. A parameter specifies the type of search to use for the specified string.
- LastIndexOf(Char, Int32, Int32): Reports the index position of the last occurrence of the specified Unicode character in a substring within this instance. The search starts at a specified character position and examines a specified number of character positions.
- LastIndexOf(String, Int32, Int32): Reports the index position of the last occurrence of a specified String within this instance. The search starts at a specified character position and examines a specified number of character positions.
- LastIndexOf(String, Int32, StringComparison): Reports the index of the last occurrence of a specified string within the current String object. Parameters specify the starting search position in the current string, and type of search to use for the specified string.
- LastIndexOf(String, Int32, Int32, StringComparison): Reports the index position of the last occurrence of a specified String object within this instance. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string.
Re: LastIndexOf in VB.NET
String: LastIndexOf in VB.NET
Sample code:
Code:
Imports System
Imports System.Collections
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim s1 As String = "One Two Three Four"
Dim index As Integer
index = s1.LastIndexOf(" ")
Dim s2 As String = s1.Substring((index + 1))
s1 = s1.Substring(0, index)
index = s1.LastIndexOf(" ")
Dim s3 As String = s1.Substring((index + 1))
s1 = s1.Substring(0, index)
index = s1.LastIndexOf(" ")
Dim s4 As String = s1.Substring((index + 1))
s1 = s1.Substring(0, index)
index = s1.LastIndexOf(" ")
Dim s5 As String = s1.Substring((index + 1))
Console.WriteLine("s1: {0}", s1)
Console.WriteLine("s2: {0}", s2)
Console.WriteLine("s3: {0}", s3)
Console.WriteLine("s4: {0}", s4)
Console.WriteLine("s5: {0}", s5)
End Sub
End Class
Output:
Quote:
s1: One
s2: Four
s3: Three
s4: Two
s5: One
Re: LastIndexOf in VB.NET
LastIndexOf belongs to "System.String" instance. It finds the last position (or IndexOf) a character or string object in a string. It is similar to the RIGHT function in Visual Basic 6. It gives you three types of values in VB.NET. If this function finds the searched character in the given string then it shows the actual position of that character; if it is not found then it returns -1 (FALSE) and if it is empty then it returns 0 (EMPTY).