无法在文件中找到字符串并使用Inno Setup填充它?

卡南

我有demo.properties文件,可以加载文件并进行迭代以获取其中的所有值。

hibernate.connection.username=jack
hibernate.connection.password=queen
hibernate.connection.url=jdbc:jtds:sqlserver://localhost/cabinet

但是当我得到第1行(能够逐行获取但无法获取特定的字符串)并且我想填充jack并将其存储到用户名String中时,类似地将Queen存入密码String中并将localhost存入数据库String中。这是我要获取的代码/逻辑价值观。

procedure InitializeWizard;
var  

  xmlInhalt: TArrayOfString;  
  k : Integer;
  CurrentLine : String;
  Uname : String;  
   Password : String;
   HostName : String;
   STR : String;                        

begin
          LoadStringsFromFile('C:\demo.properties', xmlInhalt);
          for k:=0 to GetArrayLength(xmlInhalt)<>-1 do
          begin
            CurrentLine := xmlInhalt[k];
            MsgBox(CurrentLine, mbError, MB_OK);
            if (Pos('hibernate.connection.username=', CurrentLine) <>-1 ) then
                begin
                              MsgBox(CurrentLine, mbError, MB_OK);
                    Uname := Pos('://', CurrentLine);
                    STR :=IntToStr(Uname);    
                    STR :=IntToStr(Length('://')); 
                    Password := Pos(':1', CurrentLine);
                    HostName :=Password -Uname;                  

              end;    
         end; 
end;

请帮助我达到我的要求。您的帮助将不胜感激。

TLama

如果TStrings该类已经发布NameValueSeparatorValues具有属性,我建议使用它。但这还没有,所以这是一个解决方法的代码(它使用TArrayOfString,但是很容易为TStrings该类修改它):

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Code]
function TryGetValue(const Strings: TArrayOfString; const Name: string;
  out Value: string): Boolean;
var
  S: string;
  P: Integer;
  I: Integer;
begin
  Result := False;
  { loop through the array }
  for I := 0 to GetArrayLength(Strings) - 1 do
  begin
    { store the currently iterated string into a local variable }
    S := Strings[I];
    { try to get position of the name value separator ('='in this case) }
    P := Pos('=', S);
    { if the separator was found on this line, and a text on the left of }
    { it matches (case insensitively) the input Name parameter value, we }
    { found what we were looking for, so return True and the rest of the }
    { text after the found separator }
    if (P <> 0) and (CompareText(Copy(S, 1, P - 1), Name) = 0) then
    begin
      Value := Copy(S, P + 1, MaxInt);
      Result := True;
      Exit;
    end;
  end;
end;

{ do note, that this function may not conform the RFC 3986 specification; }
{ preferred way should be e.g. InternetCrackUrl, but with this particular }
{ scheme (jdbc:jtds:sqlserver) it didn't crack the URL properly }
function GetHostName(const URL: string): string;
var
  P: Integer;
begin
  Result := '';
  P := Pos('://', URL);
  if P <> 0 then
  begin
    Result := Copy(URL, P + 3, MaxInt);
    P := Pos('/', Result);
    if P = 0 then
      P := MaxInt;
    Result := Copy(Result, 1, P - 1);
  end;
end;

procedure InitializeWizard;
var  
  URL: string;
  HostName: string;
  UserName: string;
  Password: string;
  StrArray: TArrayOfString;
begin
  if LoadStringsFromFile('C:\File.txt', StrArray) then
  begin
    TryGetValue(StrArray, 'hibernate.connection.url', URL);
    HostName := GetHostName(URL);
    TryGetValue(StrArray, 'hibernate.connection.username', UserName);
    TryGetValue(StrArray, 'hibernate.connection.password', Password);
    MsgBox(Format(
      'HostName: %s' + #13#10 + 'UserName: %s' + #13#10 + 'Password: %s', [
      HostName, UserName, Password]
    ), mbInformation, MB_OK);
  end; 
end;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在字符串中找到最长的连续字符串模式并擦除它

在Python中找到字符串中的所有子字符串,如何使它更好?

MaterialTable无法填充它

如何在java中的文件中找到一个字符串并在它旁边获取字符串?

从Inno Setup拆卸字符串[代码]

Javascript regex 在字符串中找到 %3A// 并替换它

c#如何在字符串中找到負值並轉換它?

Python无法在文件中找到字符串

Inno Setup 6不能在字符串参数中使用DLL函数,而可以在Inno Setup 5中使用

如何在我的例子中找到字符串中的特定字符“-”并在javascript js中用“_”替换它

Inno Setup替换没有BOM的UTF-8文件中的字符串

Inno Setup,如何在多个文件中搜索特定的字符串?

Inno Setup无法使用AppVeyor上的遮罩找到图像文件

Inno Setup File存在无法找到现有文件

如何在clob中找到一个特定的字符串,它的前缀是另一个字符串

使用Inno Setup将布尔值转换为字符串

如何在Inno Setup中解析JSON字符串?

在Inno Setup中比较版本字符串

Inno Setup 以字符串为参数调用 DLL

用零填充字符串后-它输出未指定的字符吗?(C ++)

使用函数在 Inno Setup 中填充的已分配字符缓冲区调用 DLL 函数

如何在字符串中找到一个字符并替换它和python中的以下一个

Java填充从文件读取的字符串

我试图在用户输入的字符串中找到一个空格,但是当我使用 indexof(" ") 它返回值 -1,我该如何解决这个问题?

Kotlin:将字符串转换为字节数组并用 0 填充它

如何创建自定义字符串并动态填充它?

Python:从字符串中检测单词并找到它的位置

什么是Windows构建字符串以及如何找到它?

无法写入我在 python 中的所有文件中找到的搜索字符串