middle

Extracts middle portion of the text between any two strings.
[middle startafter=x&endbefore=y]Any Text[/middle]
To display a subsection of some text, put the text inside a [middle] context.

Parameters

ParameterDescription
name(optional) The name of the cookie to list.
startafterString of text characters to search for defining the beginning of the text to be returned. All preceding text (and the StartAfter text itself) will be ignored.
endbeforeString of text characters to search for defining the end of the text to be returned. If several occurence of the search string appear in the text, then the last one only will be relevant. All following text (and the EndBefore text itself) will be ignored.
startbeforev8.2+ String of text characters to search for defining the beginning of the text to be returned. All preceding text will be ignored.
endafterv8.2+ String of text characters to search for defining the end of the text to be returned. All following text will be ignored.
startcountv8.2+ Can be positive or negative. Provides a means of starting from the nth occurrence of the startafter or endbefore delimiter. Default = 1.
endcountv8.2+ Can be positive or negative. Provides a means of ending from the nth occurrence of the startafter or endbefore delimiter. Default = 1.
Example WebDNA code:
[middle startafter=<body>&endbefore=</body>]
  <html>
    <head>
    </head>
    <body>
      Hi There
    </body>
  </html>
[/middle]>

Results:
The example above returns "Hi There," which is the sequence of letters between "<body>" and the last occurence of "</body>." Extracting sub-portions of text like this is useful when you need to remove the HTML header information from a file (or web page) containing HTML that you want to include inside the body of a web page.

Example WebDNA code:
Breaking up a string of text
[text]myVAR=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]

[middle startafter=f/&endbefore=/j][myVAR][/middle]
[middle startafter=f/&endbefore=/][myVAR][/middle]
[middle startafter=f/&endbefore=[url]&[/url]][myVAR][/middle]
[middle startafter=f/&endbefore=&][myVAR][/middle]
[middle startafter=f/&endbefore=/>][myVAR][/middle]

Results:
ghi
ghi/jkl/&mno/pqr/>/stu/vwx
ghi/jkl/
ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
ghi/jkl/&mno/pqr/>/stu/vwx

From WebDNA v8.2
startcount and endcount provide a means of starting/ending from the nth occurrence of the startafter or endbefore delimiter. The value can be positive or negative. A negative number counts from the opposite end it normally counts from. Positive numbers always count from the beginning. If you do not provide the startcount/endcount, the default is 1.
A startcount of -2 means "find the startafter/startbefore that is 2nd from the end of the string". Likewise, giving endcount of -2 means "find the endbefore/endafter that is 2nd from the beginning of the string".
When something isn't found, or if it isn't found n times, then it is ignored.
For example, [middle startafter=q&startcount=10]xyz[/middle] will return xyz. This is the behavior of [middle] in previous versions, to retains compatibility.

Example WebDNA code:
[middle startafter=Subject: &endbefore=%0A&endcount=-1]
Message-Id: <1874F5DF-301E-4560-8C37-63BD903EA7E4@webdna.us>
From: John Doe
To: talk@webdna.us
Content-Type: text/plain; charset=US-ASCII; format=flowed
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Apple Message framework v924)
Subject: [WebDNA] test message

Hello, this is a test
[/middle]

Results:
[WebDNA] test message
(WebDNA counts from the first line ending after the Subject:)

Example WebDNA code:
1) [middle startbefore=f/&endafter=/j][myVar][/middle]
2) [middle startafter=/&startcount=2][myVar][/middle]
3) [middle endbefore=/&endcount=3][myVar][/middle]
4) [middle endbefore=/&endcount=-3][myVar][/middle]
5) [middle startbefore=/&endafter=/][myVar][/middle]
6) [middle startafter=f/][myVar][/middle]
7) [middle endbefore=/&startcount=5][myVar][/middle]
8) [middle startbefore=f/][myVar][/middle]

Results:
1) f/ghi/j
2) ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
3) abc/def/ghi/jkl/&mno/pqr/>
4) abc/def/ghi
5) /def/ghi/jkl/&mno/pqr/>/stu/vwx/
6) ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
7) abc/def/ghi/jkl/&mno/pqr/>/stu/vwx
8) f/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?

Note result #7 the "startcount" is ignored because startcount is only used with "startbefore" and "startafter". Since no startbefore or startafter is specified, there is nothing to use startcount with. The default "endcount" of 1 is used instead since "endbefore" is specified.