@Middle (Formula Language)
Returns any substring from the middle of a string. The middle is found by scanning the string from left to right, and parameters determine where the middle begins and ends.
Syntax
@Middle( string ; offset ; numberchars ) @Middle( string ; offset ; endstring ) @Middle( string ; startString ; endstring ) @Middle( string ; startString ; numberchars )
Parameters
string
Text or text list. Any string.
offset
Number. A character position in string that indicates where you want the middle to begin, always counting from left to right. The middle begins one character after the offset.
startString
Text. A substring of string that indicates where you want the middle to begin, always counting from left to right. The middle begins one character after the end of startString.
numberchars
Number. The number of characters that you want in the middle. If numberchars is negative, the middle starts at offset or startString and continues from right to left. If numberchars is positive, the middle starts one character past the offset or startString and continues from left to right.
endstring
Text. A substring of string that indicates the end of the middle. @Middle returns all the characters between offset and endstring, or between startString and endstring.
Return value
middle
Text or text list. The substring from the middle of string, which begins at the offset or startString you specify and ends at the endstring you specify, or after the numberchars have been reached.
Usage
If the first parameter is a list, the function operates on each element of the list, and the return value is a list with the same number of elements.
Examples
- This example returns h C. The offset is positioned at the "t"
(the fourth character from the left), and the count starts with the
first character after the offset, moving from left to right.
@Middle("North Carolina";4;3)
- This example returns ort. The offset is positioned at the "t"
(the fourth character from the left), and the count begins at the
offset, moving from right to left.
@Middle("North Carolina";4;-3)
- This example returns Car. The offset is positioned at the first
space in the string "North Carolina" and the count starts with the
first character after the offset.
@Middle("North Carolina";" ";3)
- This example returns or. The offset is positioned at the substring
"th" and the count starts with the first character after the entire
offset, moving from right to left.
@Middle("North Carolina";"th";-2)
- This example returns " is the " with spaces before and after "is
the." The return string is everything from the fifth character through
the character before "text."
@Middle("This is the text"; 4; "text")
- This example returns " the " with a space before and after "the."
The return string is everything after " is" and before "text." The
startString " is" begins with a space; this prevents @Middle from
returning a string that starts at the "is" in the word "This."
@Middle("This is the text"; " is"; "text")
- This example returns "Hello" and "This" in a list. The offset
is the beginning of each text element and the end text is the first
space.
@Middle("Hello world" : "This is the time"; 0; " ")