IndexOf

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi,
I want to check if there are 3 underlines (not less, not more) in a string?
I know I can use IndexOf, but it will only return the location of first occur.
How can I check this in .NET 2?
Thanks:)
 
IndexOf overloads

The IndexOf method has overloads which take a starting position, which will allow you to start each search from the position of the previous underscore:

Visual Basic:
Dim count As Integer
Dim pos As Integer

count = 0
pos = someString.IndexOf("_"c)
While (pos > -1)
    count = count + 1
    pos = someString.IndexOf("_"c, pos + 1)
End While

Good luck :cool:
 
Back
Top