Advertisement
phamchin

FindNthChar

Feb 21st, 2023 (edited)
1,482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.42 KB | None | 0 0
  1. Function FindNthChar(str As String, ch As String, n As Integer) As Integer
  2.     Dim pos As Integer
  3.     Dim i As Integer
  4.     Dim cnt As Integer
  5.     pos = 0
  6.     cnt = 0
  7.     For i = 1 To Len(str)
  8.         If Mid(str, i, 1) = ch Then
  9.             cnt = cnt + 1
  10.             If cnt = n Then
  11.                 pos = i
  12.                 Exit For
  13.             End If
  14.         End If
  15.     Next i
  16.     FindNthChar = pos
  17. End Function
  18.  
Tags: excel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement