- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 字符串分割
字符串分割:
//--------------------------------------------------------------------------------
var
str: string;
arr: TArray;
begin
str := 'A-1,B-2,,,C-3,D-4';
arr := str.Split([',']); // arr[0] = A-1; Length(arr) = 6
arr := str.Split([','], TStringSplitOptions.ExcludeEmpty); // 忽略空项; Length(arr) = 4
arr := str.Split([','], 2); // 只提取前 2
arr := str.Split([',', '-'], ExcludeEmpty); //arr[0] = A; Length(arr) = 8
arr := str.Split([',,,'], None); // 分隔符可以是一个字符串数组
end;