遍历字符串数组 - 类型不匹配
Looping through an array of strings - Type mismatch
我正在尝试拆分一个 csv 字符串,然后遍历数组并更改这些字符串,然后再次将其构建回以逗号分隔的字符串。
function StrSplit(Text: String; Separator: String): Array of String;
var
i, p: Integer;
Dest: Array of String;
begin
i := 0;
repeat
SetArrayLength(Dest, i+1);
p := Pos(Separator,Text);
if p > 0 then begin
Dest[i] := Copy(Text, 1, p-1);
Text := Copy(Text, p + Length(Separator), Length(Text));
i := i + 1;
end else begin
Dest[i] := Text;
Text := '';
end;
until Length(Text)=0;
Result := Dest
end;
function FormatHttpServer(Param: String): String;
var
build: string;
s: string;
ARRAY1: Array of String;
begin
ARRAY1 := StrSplit(param, ',');
build:='';
for s in ARRAY1 do
begin
build := build + DoSomething(C);
end;
end;
我从别处打电话给 FormatHttpServer
。我无法让脚本编译,因为在下一行我得到一个 "type mismatch error" 并且我不明白为什么。它应该使用字符串 s 遍历字符串数组。
for s in ARRAY1 do
Inno Setup Pascal 脚本不支持 for ... in
语法。
您必须使用索引:
var
I: Integer;
A: array of string;
S: string;
begin
A := { ... };
for I := 0 to GetArrayLength(A) - 1 do
begin
S := A[I];
{ Do something with S }
end;
end;
我正在尝试拆分一个 csv 字符串,然后遍历数组并更改这些字符串,然后再次将其构建回以逗号分隔的字符串。
function StrSplit(Text: String; Separator: String): Array of String;
var
i, p: Integer;
Dest: Array of String;
begin
i := 0;
repeat
SetArrayLength(Dest, i+1);
p := Pos(Separator,Text);
if p > 0 then begin
Dest[i] := Copy(Text, 1, p-1);
Text := Copy(Text, p + Length(Separator), Length(Text));
i := i + 1;
end else begin
Dest[i] := Text;
Text := '';
end;
until Length(Text)=0;
Result := Dest
end;
function FormatHttpServer(Param: String): String;
var
build: string;
s: string;
ARRAY1: Array of String;
begin
ARRAY1 := StrSplit(param, ',');
build:='';
for s in ARRAY1 do
begin
build := build + DoSomething(C);
end;
end;
我从别处打电话给 FormatHttpServer
。我无法让脚本编译,因为在下一行我得到一个 "type mismatch error" 并且我不明白为什么。它应该使用字符串 s 遍历字符串数组。
for s in ARRAY1 do
Inno Setup Pascal 脚本不支持 for ... in
语法。
您必须使用索引:
var
I: Integer;
A: array of string;
S: string;
begin
A := { ... };
for I := 0 to GetArrayLength(A) - 1 do
begin
S := A[I];
{ Do something with S }
end;
end;