将固定字符分隔的内容转换为数组
1 function Split(const Source, ch: string): TStringList;
2 var
3 Temp: string;
4 I: Integer;
5 chLength: Integer;
6 tmpStr: string;
7 begin
8 Result := TStringList.Create;
9 //如果是空自符串则返回空列表
10 if Source = '' then Exit;
11 Temp := Source;
12 I := Pos(ch, Source);
13 chLength := Length(ch);
14 while I <> 0 do
15 begin
16 tmpStr := Copy(Temp, 0, I - chLength + 1);
17 if tmpStr[Length(tmpStr)] = ch then
18 tmpStr := Copy(tmpStr, 0, Length(tmpStr) - 1);
19 Result.Add(tmpStr);
20 Delete(Temp, 1, I - 1 + chLength);
21 I := pos(ch, Temp);
22 end;
23 Result.add(Temp);
24 end;
2 var
3 Temp: string;
4 I: Integer;
5 chLength: Integer;
6 tmpStr: string;
7 begin
8 Result := TStringList.Create;
9 //如果是空自符串则返回空列表
10 if Source = '' then Exit;
11 Temp := Source;
12 I := Pos(ch, Source);
13 chLength := Length(ch);
14 while I <> 0 do
15 begin
16 tmpStr := Copy(Temp, 0, I - chLength + 1);
17 if tmpStr[Length(tmpStr)] = ch then
18 tmpStr := Copy(tmpStr, 0, Length(tmpStr) - 1);
19 Result.Add(tmpStr);
20 Delete(Temp, 1, I - 1 + chLength);
21 I := pos(ch, Temp);
22 end;
23 Result.add(Temp);
24 end;