margret Well-Known Member Licensed User Longtime User Mar 23, 2012 #1 I need to be able to find like the 4th and 10th occurrence in a string. I looked through the docs and found First and Last occurrence, but nothing in between. I can use Regex and a few lines of code but was looking for a single function to do this with. Are there any functions or Libs I can use to do this, something like: MyVar.IndexOf("#", 4) MyVar.IndexOf("#", 10)
I need to be able to find like the 4th and 10th occurrence in a string. I looked through the docs and found First and Last occurrence, but nothing in between. I can use Regex and a few lines of code but was looking for a single function to do this with. Are there any functions or Libs I can use to do this, something like: MyVar.IndexOf("#", 4) MyVar.IndexOf("#", 10)
Ricky D Well-Known Member Licensed User Longtime User Mar 24, 2012 #2 Not that I know of but you could create a sub to do it kind of like Code: Copy Sub GetWord(str As String, wordnumber As Int) As String Dim ret as String ret = "" Dim s() As String s = Regex.Split(" ",str) If wordnumber<=s.Length Then ret = s(wordnumber-1) End If Return ret End Sub I just tested this on my Galaxy s2 and works fine. Code: Copy GetWord("the quick brown fox", 2) 'returns quick GetWord("the quick brown fox", 7) 'returns empty string regards, Ricky Upvote 0
Not that I know of but you could create a sub to do it kind of like Code: Copy Sub GetWord(str As String, wordnumber As Int) As String Dim ret as String ret = "" Dim s() As String s = Regex.Split(" ",str) If wordnumber<=s.Length Then ret = s(wordnumber-1) End If Return ret End Sub I just tested this on my Galaxy s2 and works fine. Code: Copy GetWord("the quick brown fox", 2) 'returns quick GetWord("the quick brown fox", 7) 'returns empty string regards, Ricky