-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathUStringSplitter.pas
60 lines (48 loc) · 1.44 KB
/
UStringSplitter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
unit UStringSplitter;
(******************************************************************************
* Description: Token-based string splitter *
* Author: Alexandru Tuduran *
* Contact: [email protected] *
( *****************************************************************************)
interface
{$WARN UNIT_PLATFORM OFF}
{$WARN SYMBOL_PLATFORM OFF}
uses
Classes,
SysUtils,
Dialogs;
function Splitter_Split_Strings(Source: String; Separator: Char): TStringList;
function Splitter_Get_Next_Token(S: String; var Index: Integer; Separator: Char): String;
implementation
{ Interface routines }
function Splitter_Split_Strings(Source: String; Separator: Char): TStringList;
var
SL: TStringList;
Index: Integer;
begin
//create splits;
SL := TStringList.Create;
//find splits using tokenizer;
Index := 1;
repeat
SL.Add(Splitter_Get_Next_Token(Source, Index, Separator));
until Index > Length(Source);
//return
Result := SL;
end;
function Splitter_Get_Next_Token(S: String; var Index: Integer; Separator: Char): String;
var
Token: String;
begin
Token := '';
while Index <= Length(S) do
begin
if S[Index] = Separator then
Break;
Token := Token + S[Index];
Inc(Index);
end;
Inc(Index);
Result := Token;
end;
end.