inno-setup – Innosetup中的字符串数组
发布时间:2020-12-15 09:06:56 所属栏目:大数据 来源:网络整理
导读:我试图在一行中的InnoSetup中的子字符串后得到一个特定的整数.有Trim,TrimLeft,TrimRight函数但没有子串提取函数. 示例: line string: 2345line another string: 3456 我想提
|
我试图在一行中的InnoSetup中的子字符串后得到一个特定的整数.有Trim,TrimLeft,TrimRight函数但没有子串提取函数.
示例: line string: 2345 line another string: 3456 我想提取“2345”和“3456”. 我正在加载数组中的文件内容,但无法通过array [count] [char_count]取消引用它. 解决方法
我将输入文件加载到TStrings集合并逐行迭代.对于每一行,我会找到一个“:”字符位置,从这个位置我将复制我最终修剪的字符串.步骤:
1. line string: 2345 2. 2345 3. 2345 现在仍然要将这样的字符串转换为整数并将其添加到最终集合中.由于你在文件样本中显示了一个空行,并且由于你没有说过这种格式是否总是被修复,所以让我们以安全的方式转换这个字符串. Inno Setup为这个安全转换提供了一个功能,即 [Code]
type
TIntegerArray = array of Integer;
procedure ExtractIntegers(Strings: TStrings; out Integers: TIntegerArray);
var
S: string;
I: Integer;
Value: Integer;
begin
for I := 0 to Strings.Count - 1 do
begin
// trim the string copied from a substring after the ":" char
S := Trim(Copy(Strings[I],Pos(':',Strings[I]) + 1,MaxInt));
// try to convert the value from the previous step to integer;
// if such conversion fails,because the string is not a valid
// integer,it returns -1 which is treated as unexpected value
// in the input file
Value := StrToIntDef(S,-1);
// so,if a converted value is different from unexpected value,// add the value to the output array
if Value <> -1 then
begin
SetArrayLength(Integers,GetArrayLength(Integers) + 1);
Integers[GetArrayLength(Integers) - 1] := Value;
end;
end;
end;
procedure InitializeWizard;
var
I: Integer;
Strings: TStringList;
Integers: TIntegerArray;
begin
Strings := TStringList.Create;
try
Strings.LoadFromFile('C:File.txt');
ExtractIntegers(Strings,Integers);
for I := 0 to GetArrayLength(Integers) - 1 do
MsgBox(IntToStr(Integers[I]),mbInformation,MB_OK);
finally
Strings.Free;
end;
end;
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
