middle, middle include, middle until, middle until include
This function extracts a middle part of the string either with two character position numbers or matching patterns or a combination of both.
Indirect parameter passing is disabled
3
No. | Type | Description |
---|---|---|
1 input |
valid types | input string or value Attention: If 1st parameter is a parameter set, please refer to middle [parameter set function] instead. |
2 input |
numeral | starting character position Positive: String begins with specified character position (0 = 1st character, 1 = 2nd character, etc.) |
Alt. 2 input |
string | starting matching pattern Function middle ...: Middle part of the string begins after the starting matching pattern. |
3 input |
numeral | character count or ending character position For function names middle and middle include, this parameter specifies the number of characters to include. |
Alt. 3 input |
string | ending matching pattern Function middle ...: Middle part of the string ends before the ending matching pattern. |
Type | Description |
---|---|
string | Extracted substring |
st[] = "The taste of the coffee!";
echo( middle( st[], 4, 8 ), " / ", middle until ( st[], 4, 8 ) );
echo( middle( st[], -6, 3 ), " / ", middle until( st[], -7, -2 ) ); // "off", "coffee"
echo;
echo( middle( st[], 99, 8 ), " / ", middle until ( st[], 99, 8 ) ); // empty strings
echo( middle( st[], -99, 8 ), " / ", middle until ( st[], -99, 8 ) );
echo;
echo( middle( st[], 'taste ', 13 ), " / ", middle include( st[], 'taste ', 13 ) ); // "of the coffee", "tast of the coffee"
echo;
echo( middle until( st[], 'taste ', -2 ), " / ", middle until include( st[], 'taste ', -2 ) ); // "of the coffee", "tast of the coffee"
echo( middle until include( st[], 'taste ', 3 ), " / ", middle until include( st[], 'taste ', 6 ) ); // "", "tas"
echo;
echo( middle ( st[], 'taste ', ' coffee' ), " / ", middle include( st[], 'taste ', ' coffee' ) ); // "of the", "tast of the coffee"
taste of / taste
off / coffee
/
The tast / The taste
of the coffee / taste of the coffee
of the coffee / taste of the coffee
/ tas
of the / taste of the coffee
left [string function]
right [string function]
outside [string function]
middle [parameter set function]