Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:)

Posted

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:

 

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:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...