Technical References - [middle]

Extracts middle portion of the text between any two strings.

numero = 270
interpreted = N
texte = [middle startafter=x&endbefore=y]Any Text[/middle] To display a subsection of some text, put the text inside a [middle] context. Example:
[middle startafter=<body>&endbefore=</body>]<html><head></head><body>Hi There</body></html>[/middle]
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. The following parameters are required in the [middle] context:
ParameterDescription
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.
startbefore(Available from v8.2) String of text characters to search for defining the beginning of the text to be returned. All preceding text will be ignored.
endafter(Available from v8.2) String of text characters to search for defining the end of the text to be returned. All following text will be ignored.
Example string: abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?
[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 v8.2
[middle startafter=Subject: &endbefore=%0A&endcount=-1]Message-Id: <1874F5DF-301E-4560-8C37-63BD903EA7E4@zarcrom.com>From: Joshn Doe To: talk@webdna.usContent-Type: text/plain; charset=US-ASCII; format=flowedContent-Transfer-Encoding: 7bitMime-Version: 1.0 (Apple Message framework v924)Subject: [WebDNA] test messageHello, this is a test[/middle]
Result: [WebDNA] test message (WebDNA counts from the first line ending after the Subject:)

startcount and endcount can be positive or negative. A negative number counts from the opposite end it normally counts from. Positive numbers always count from the traditional direction that old WebDNA versions counted from. If you do not provide the startcount/endcount, they default to 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 enough times, then it ignores it. So for example, [middle startafter=q&startcount=10]xyz[/middle] will return xyz. This is the behavior of [middle] in previous versions, so it retains compatibility.

[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]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?

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

[middle startafter=x&endbefore=y]Any Text[/middle]

To display a subsection of some text, put the text inside a [middle] context.

Example:

[middle startafter=<body>&endbefore=</body>]
<html>
<head>
</head>
<body>
Hi There
</body>
</html>
[/middle]

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.

The following parameters are required in the [middle] context:

ParameterDescription
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.
startbefore(Available from v8.2) String of text characters to search for defining the beginning of the text to be returned. All preceding text will be ignored.
endafter(Available from v8.2) String of text characters to search for defining the end of the text to be returned. All following text will be ignored.


Example string: abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?

[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 v8.2

[middle startafter=Subject: &endbefore=%0A&endcount=-1]
Message-Id: <1874F5DF-301E-4560-8C37-63BD903EA7E4@zarcrom.com>
From: Joshn 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]


Result:
[WebDNA] test message

(WebDNA counts from the first line ending after the Subject:)

startcount and endcount can be positive or negative. A negative number counts from the opposite end it normally counts from. Positive numbers always count from the traditional direction that old WebDNA versions counted from. If you do not provide the startcount/endcount, they default to 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 enough times, then it ignores it. So for example, [middle startafter=q&startcount=10]xyz[/middle] will return xyz. This is the behavior of [middle] in previous versions, so it retains compatibility.



[text]myVar=abc/def/ghi/jkl/&mno/pqr/>/stu/vwx/>yz?[/text]

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?

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



DOWNLOAD WEBDNA NOW!

Top Articles:

Download WebDNA Applications

WebDNA applications...

F.A.Q

A compilation of some user's questions...

Tips and Tricks

A list of user-submitted tips ...

WebDNA Libraries

A list of available libraries for WebDNA...

WebDNA Modules

A list of the currently available modules...

Technical Change History

This Technical Change History provides a reverse chronological list of WebDNA changes...

Related Readings:

[referrer]

Displays the URL of the referring page...

[search]

Use the [Search] context with [founditems] to easily retrieve records from your databases...

[tcpsend]

A powerful feature that sends text to a TCP server program on a remote machine...

[cookie]

Cookies are a great way to remember visitors...

[version]

...

[writefile]

[writefile] functions allows you to perform a wide variety of tasks...