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

例如,如果我的string是

快乐的歌

输出应该是

页。

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

以下是我的答案。 我还添加了逻辑来检查是否有第二个元音,如果没有,则会引发错误string。 详情请参阅截图。

= IF(A1 <> “”,IFERROR(MID(A1,FIND( “|”,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1), “一”, “|”), “E”,” | “)中,” i”, “|”), “O”, “|”), “U”, “|”),FIND( “|”,SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1 ), “一”, “|”), “E”, “|”)中, “i”, “|”), “O”, “|”), “U”, “|”))+ 1) +1,1),“找不到第二个元音”),“”)

在这里输入图像描述

这会在第二个元音之后find字母:

=IF(A1<>"",MID(A1,FIND("}}}",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(LOWER(A1),"a","}"),"e","}"),"i","}"),"o","}"),"u","}"),"y","}"),"}","}}}",2))+1,1),"") 

![在这里输入图片描述

VBA回答(有评论)是;

 Function AfterSecondVowel(InputRange As String) 'Put all the ascii codes for vowels (upper and lower case) in an array asciicodesforvowels = Array(65, 97, 69, 101, 73, 105, 79, 111, 85, 117) Dim Counter As Integer Dim i As Integer Counter = 0 'Loop through all the letters in the input string For i = 1 To Len(InputRange) 'Check to see if trying to match the current letter (converted to an ascii code) you are on from the input range 'is in the array of ascii codes - If it isn't this will throw an error If Not IsError(Application.Match(Asc(Mid(InputRange, i, 1)), asciicodesforvowels, False)) Then 'Increment your counter by 1 Counter = Counter + 1 End If 'Check to see if the counter has reached 2 yet - You can change the = 2 bit here to any number you want to return 'the letter after the N'th vowel If Counter = 2 Then 'If it has reached the second vowel, skip to the next letter i = i + 1 'Set the output of the function to this letter you've moved to AfterSecondVowel = Mid(InputRange, i, 1) 'Exit the function Exit Function End If 'Otherwise loop through to the next letter Next i 'If you reach the end of the letters without exiting the function it's because there weren't 'two vowels so exit the function returning the string value 'Nothing' AfterSecondVowel = "Nothing" End Function 

这将按照你的规范返回值,只有你没有指定的是如果第二个元音是最后一个字母它应该如何performance – 上面只会返回一个空string。

假设你有这样的数据设置,用你的短语开始单元格A1并向下列A:

tigerravatar Deeksha Jha的例子

select单元格B1并select该单元格,创build一个命名范围。 我将它命名为LetterAfterVowel2并使用以下公式进行定义:

 =MID($A1,MIN(SEARCH({"a","e","i","o","u","y"},$A1&"aieouy",MIN(SEARCH({"a","e","i","o","u","y"},$A1&"aieouy"))+1))+1,1) 

现在我们不必每次都input那些乱七八糟的东西,这使得完成的配方更加清洁。 在单元格B1中复制下来的是这个公式:

 =IF(A1="","",IF(LetterAfterVowel2=" ","Nothing",LetterAfterVowel2))