如何在string中find第二个元音之后的字符

我想这个如何在EXCEL中的string中find第二个元音之后的字符? 很有趣,除了太宽泛。

加上我已经回答了,但为时已晚。

例如,如果我的string是

快乐的歌

输出应该是

页。

如果是空白,则显示“无”

解决scheme

一个公式的方法(礼貌tikkaty

=IF(A1<>"",IFERROR(MID(A1,FIND("|",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1),"a","|"),"e","|"),"i","|"),"o","|"),"u","|"),FIND("|",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1),"a","|"),"e","|"),"i","|"),"o","|"),"u","|"))+1)+1,1),"no second vowel found"),"")

这是一个无正则expression式的变体:

 Function charTest(s As String) As String Dim i As Integer, j As Integer, r As String For i = 1 To Len(s) If UCase(Mid(s, i, 1)) Like "[AEIOU]" Then j = j + 1 If j >= 2 Then Exit For Next i If j >= 2 And i < Len(s) Then r = Mid(s, i + 1, 1) If r = "" Then r = "Nothing" charTest = r End Function 

validation:

 Sub test2() Debug.Print charTest("abcdefghijkl") Debug.Print charTest("Excellence") Debug.Print charTest("Animal") Debug.Print charTest("The guppy pond") Debug.Print charTest("The smallest bike") Debug.Print charTest("Shea") End Sub 

F


p

没有

一个可能的VBA UDF解决scheme:

testing代码

 Sub test() Debug.Print StrOut("The Happy Song") Debug.Print StrOut("The Gypsy") Debug.Print StrOut("1234") End Sub 

UDF

 Function StrOut(strIn As String) As String Dim objRegex As Object Dim objRegexM As Object Set objRegex = CreateObject("vbscript.regexp") With objRegex .Pattern = "[aeiou].*?[aeiou](.)" If .test(strIn) Then Set objRegexM = .Execute(strIn) strOut = objRegexM(0).submatches(0) Else StrOut = "Nothing" End If End With End Function