ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Finding a Substring? (https://www.excelbanter.com/excel-worksheet-functions/131883-finding-substring.html)

Jakobshavn Isbrae

Finding a Substring?
 
How can I find the last occurrence of a substring with a larger string?
--
jake

Ron Coderre

Finding a Substring?
 
Try something like this:

With
A1: abcaaaaaaaaaadddddddabczzzzzzzzzzzzzabcyyyyy

This formul returns the starting position of the last occurrence of "abc"
=SEARCH("|",SUBSTITUTE(A1,"abc","|",(LEN(A1)-LEN(SUBSTITUTE(A1,"abc","")))/LEN("abc")))

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Jakobshavn Isbrae" wrote:

How can I find the last occurrence of a substring with a larger string?
--
jake


joel

Finding a Substring?
 
I'm in the mood today to write my own functions. try this

Function FindLast(ShortString, LongString) As Integer

Shortlength = Len(ShortString)
LongLength = Len(LongString)

FindLast = 0
If (Shortlength <= LongLength) Then

StringPosition = LongLength - Shortlength + 1

For i = StringPosition To 1 Step -1

If (StrComp(ShortString, Left(Mid(LongString, i, Shortlength),
Shortlength)) = 0) Then
FindLast = i
Exit For
End If


Next i

End If

End Function

"Jakobshavn Isbrae" wrote:

How can I find the last occurrence of a substring with a larger string?
--
jake


Jakobshavn Isbrae

Finding a Substring?
 
Thank you.

This is something I can use.
--
jake


"Ron Coderre" wrote:

Try something like this:

With
A1: abcaaaaaaaaaadddddddabczzzzzzzzzzzzzabcyyyyy

This formul returns the starting position of the last occurrence of "abc"
=SEARCH("|",SUBSTITUTE(A1,"abc","|",(LEN(A1)-LEN(SUBSTITUTE(A1,"abc","")))/LEN("abc")))

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


"Jakobshavn Isbrae" wrote:

How can I find the last occurrence of a substring with a larger string?
--
jake


Jakobshavn Isbrae

Finding a Substring?
 
Thank you very much.


--
jake


"Joel" wrote:

I'm in the mood today to write my own functions. try this

Function FindLast(ShortString, LongString) As Integer

Shortlength = Len(ShortString)
LongLength = Len(LongString)

FindLast = 0
If (Shortlength <= LongLength) Then

StringPosition = LongLength - Shortlength + 1

For i = StringPosition To 1 Step -1

If (StrComp(ShortString, Left(Mid(LongString, i, Shortlength),
Shortlength)) = 0) Then
FindLast = i
Exit For
End If


Next i

End If

End Function

"Jakobshavn Isbrae" wrote:

How can I find the last occurrence of a substring with a larger string?
--
jake



All times are GMT +1. The time now is 04:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com