BetweenNext ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean )_
Rate this function: Average rating: 4.4 (7 votes) Discuss this Custom Function
Fabrice Nordmann, 1-more-thing
http://www.1-more-thing.com
extracts the middle of a text in between delimiters, based on search strings and an occurrence numbers
Sample Input:
| BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 ) |
|
Sample Output:
|
Description:
/*
BetweenNext ( _text ; _searchString1 ; _occurrence1 ; _include1_boolean ; _searchString2 ; _occurrence2 ; _include2_boolean )
by Fabrice Nordmann
v.1.5, Jan 2009
bug fix with short searchString
optimisation
v.1.1.1, Apr 2008
bug fix : if string2 was in string1, result would be erroneous
v.1.1, Feb 2008
returns empty if searchString1 is not found
v.1, Mar 2007
extracts the middle of a text in between delimiters, based on a search strings and an occurrence numbers
occurrences can be positive (starting from the beginning of the text) or negative (starting from the end)
The second string will be found only after the first one.
Both string can be included or excluded with boolean parameters.
e.g : BetweenNext ( "A 1234567890 X B 1234567890 X C 1234567890 X" ; "B" ; 1 ; 1 ; "X" ; 1 ; 0 )
= "B 1234567890 "
see also Between, Before and After functions
*/
Let ([
_occurrence1 = Case ( _occurrence1 = 0 ; 1 ; _occurrence1 )
; _occurrence2 = Case ( _occurrence2 = 0 ; 1 ; _occurrence2 )
; _lenStr1 = Length ( _searchString1 )
; _p1= Position ( _text ; _searchString1 ; Case ( _occurrence1 < 0 ; Length ( _text ) ; 1 ) ; _occurrence1 )
; _rightText = Replace ( _text ; 1 ; _p1 + _lenStr1 - 1 ; "" )
; _p2= Position ( _rightText ; _searchString2 ; Case ( _occurrence2 < 0 ; Length ( _rightText ) ; 1 ) ; _occurrence2 )
; _content = Left ( _rightText ; _p2 - 1 )
]
;
Case ( _p1 and _p2
; Case ( _include1_boolean ; _searchString1 ) & _content & Case ( _include2_boolean ; _searchString2 )
)
)
Note: these functions are not guaranteed
or supported by BrianDunning.com. Please contact the individual
developer with any questions or problems.
This is my Custom Function and I want to
edit it
Discuss:There are no comments yet. Be the first to post a comment about this Custom Function! Please try to keep it brief & to the point. Anyone can post:
|
Newest Custom Functions:
| 1. |
webviewer_button ( content; textCol; bgCol ) |
| |
(Wed, Mar 03, 11:18am) |
| 2. |
RemoveCommonValues ( Array ; ComparisonArray ) |
| |
(Wed, Feb 24, 9:39pm) |
| 3. |
DistanceGeoCoord ( Lat1deg ; Lat1mm ; Lat1ss ; Lon1deg ; Lon1mm ; Lon1ss ; Lat2deg ; Lat2mm ; Lat2ss ; Lon2deg ; Lon2mm ; Lon2ss ; U ; Version ) |
| |
(Wed, Feb 24, 2:20pm) |
| 4. |
fnGoogleLineChart ( chtitle ; xtitle ; ytitle ; xfield ; yfield ; color ) |
| |
(Tue, Feb 23, 1:30pm) |
| 5. |
StringConstruct ( text ; prefix ; suffix ; altText ) |
| |
(Fri, Feb 19, 10:57am) |
| 6. |
ShowValueCascade ( fields ; altText ) |
| |
(Fri, Feb 19, 10:44am) |
| 7. |
ShowValue ( text; altText ) |
| |
(Fri, Feb 19, 10:28am) |
| 8. |
timeFormat ( thetime ; leader ) |
| |
(Wed, Feb 17, 7:44pm) |
 |
|