Xbasic

EXTRACT_ALL_STRINGS Function

Syntax

Sub_String as C = extract_all_strings(C string ,C start_string ,C end_string [,C delimiter[,L include_tags [,L case_sensitive [,L regex_safe ]]]])

Arguments

stringCharacter

The string to examine for the find text.

start_stringCharacter

The beginning characters of the find text.

end_stringCharacter

The ending characters of the find text.

delimiterCharacter

Default = CR-LF. The character(s) to insert between instances of the found text.

include_tagsLogical

Default = .F.

.T. = Include the Start_Find and Start_Find characters.

.F. = Return only the text between the Start_Find and Start_Find characters.

case_sensitiveLogical

Default = .F.

.T. = Case sensitive.

.F. = Case insensitive.

regex_safeLogical

Default = .F. The "unsafe" characters are ., |, *, ?, +, (, ), {, }, , , ^, $ and \. If your Start_Find and End_Find do not contain any of these characters, you should set Regex_Safe to true to maximize performance.

.T. = Improves performance by declaring that the start and end tags are already regular expression safe and EXTRACT_STRING() does not need to escape special characters.

.F. = Unsafe characters are replaced. This decreases performance on a large string.

Returns

Sub_StringCharacter

The string extracted from Search_in_String.

Description

Extracts the all occurrences of a sub-string starting with start_string and ending with end_string.

Discussion

The EXTRACT_ALL_STRINGS() function returns all occurrences of text beginning and ending with specified character sequences.

Example

dim tags as C

html = <<%html%
<html>
<head>
<title>My Home Page</title>
</head>
<body bgcolor="white">
<h2>Welcome to my home page</h2>
I hope you like it
</body></html>
%html%

? extract_string(html,"<",">")
= "html"

? extract_string(html,"<",">",3)
= "title"

? extract_all_strings(html,"<",">")
= html
head
title
/title
/head
body bgcolor="white"
h2
/h2
/body
/html

? extract_all_strings(html,"<",">","~")
= html~head~title~/title~/head~body bgcolor="white"~h2~/h2~/body~/html