Unit classes
Syntax
[Delphi] function extractstrings (separators: tsyscharset; whitespace: tsyscharset; content: pansichar; strings: tstrings): integer;
Description use extractstrings to fill a string list with the substrings of the null-terminated string specified by content.
Separators is a set of characters that are used as delimiters, separating the substrings. carriage returns, newline characters, and quote characters (single or double) are always treated as separators. separators are ignored when inside a quoted string until the final end quote. (Note that quoted characters can appear in a quoted string if the quote character is doubled .)
Whitespace is a set of characters to be ignored when parsing Content if they occur at the beginning of a string.
Content is the null-terminated string to parse into substrings.
Strings is a string list to which all substrings parsed from content are added. the string list is not cleared by extractstrings, so any strings already in the string list are preserved. extractstrings returns the number of strings added to the strings parameter. note:
Extractstrings does not add empty strings to the list.
[Update]:
The separators parameter specifies a group of delimiters. All substrings are separated by them. However, the separators in the pair quotation marks are ignored (see the example below ).
The whitespace parameter specifies the character s that is ignored at the beginning of each substring.
The content parameter is the split "Source" string.
The strings parameter is used to receive split substrings. Its original content will not be cleared. Don't forget to create.
In addition, ectractstrings do not add null strings (after whitespaces is ignored) to strings.
Write an example:
For example
ABC |... Def | #### Ghi | "not separated | # www.farproc.com"
To get
ABC
Def
Ghi
Not separated | # www.farproc.com
The following code can be used for the four substrings:
Uses
Classes;
VaR
Asource: pchar;
Astr: string;
Acount: integer;
Astrings: tstringlist;
Begin
Asource: = 'abc |... Def | #### Ghi | "not separated | # www.farproc.com "';
Astrings: = tstringlist. Create;
Try
Acount: = extractstrings (['|'], ['', '#', '.'], asource, astrings );
{Do any further processing}
/For astr in astrings do
// Writeln (astr );
Finally
Astrings. Free;
End;
Readln;
End.