String 删除字符串的特定部分

String 删除字符串的特定部分,string,inno-setup,pascal,String,Inno Setup,Pascal,我正在使用Pascal脚本返回基于注册表项的字符串,但我需要删除该字符串的特定部分 以下是当前代码: function GetDirName(Value: string): string; var InstallPath: string; begin // initialize default path, which will be returned when the following registry // key queries fail due to mi

我正在使用Pascal脚本返回基于注册表项的字符串,但我需要删除该字符串的特定部分

以下是当前代码:

function GetDirName(Value: string): string;
var          
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := '{pf}\LucasArts\Star Wars Battlefront II\RegistryFailed';
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath
end;
我需要从返回字符串中删除的部分是\BattlefrontII.exe,它始终位于字符串的最末端

当前返回字符串的示例:
C:\ProgramFiles(x86)\Lucasart\Star Wars Battlefront II\GameData\BattlefrontII.exe

我需要返回的字符串看起来或多或少类似的示例:
C:\ProgramFiles(x86)\lucasart\Star Wars Battlefront II\GameData

感谢您的帮助


另外,我对帕斯卡完全陌生;我只是用它来使用Inno Setup Compiler编译安装程序

描述:提取给定文件的驱动器和目录部分 名称结果字符串是文件名最左边的字符,最多 指向并包括分隔路径的冒号或反斜杠 来自名称和扩展名的信息。结果字符串为空 如果文件名不包含驱动器和目录部分

有关更多有用的内容,请参阅

在你的情况下,你可以这样说:

Result := ExtractFilePath(Result);
在你的功能结束时

编辑:要特别明确:

function GetDirName(const Value: string): string;
var          
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := ExpandConstant('{pf}\LucasArts\Star Wars Battlefront II\RegistryFailed');
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath  
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath;

  // return only the path
  Result := ExtractFilePath(Result);
end;

谢谢你的信息。但我到底应该如何实现这一点呢?(通常情况下,我可以自己解决这类问题,但我对语法和语言本身还是非常陌生。)这相当简单。编辑。>暗示我至少知道自己在做什么——不知道,但我还是不明白;将其放在函数末尾会在编译时出现错误。一秒钟后,我尝试了几件事。>一点也不接近4chan>暗示着我的事情——编辑得非常明确:)@user3639133,你很接近:-)你只是错过了
位于阻止您编译的语句末尾。OT:从不显式查询
Wow6432Node
注册表路径。而是使用直接路径和
HKLM32
HKLM64
作为根键。你可以在章节中找到他们的描述。有什么原因吗?(注意:我的安装程序只读取注册表项,不写入任何项。)维护起来更容易,但更重要的是,您将使用系统重定向器,它将您重定向到正确的注册表视图路径。谁知道呢,也许微软决定将
Wow6432Node
重命名为
Wow1234Node
,这将意味着一个重定向节点,从那时起,你的硬代码就不走运了。我已经恢复了你的编辑,因为你在收到原始答案后修改了问题。请不要那样做;它会使以前的答案无效,会让回答的人看起来很愚蠢,在某些情况下会损害他们的声誉,而这些对那些花时间试图帮助你的人来说都不是很好。如果你有一个新问题,发布一个新问题。“我更改了我的代码(现在是这个新代码),但仍然不起作用。它现在有一个不同的问题。”是一个新问题。这不是“进化我的代码”-这是问题和答案。有人会期望“编辑:”位将其全部置零,但不管我怎么猜。我的错。不习惯这种风格的论坛。至于我的问题,我相信问题已经解决了。如果问题仍然存在,将让您知道(使用新问题:D)。非常感谢你们所有人。:)
function GetDirName(const Value: string): string;
var          
  InstallPath: string;
begin
  // initialize default path, which will be returned when the following registry
  // key queries fail due to missing keys or for some different reason
  Result := ExpandConstant('{pf}\LucasArts\Star Wars Battlefront II\RegistryFailed');
  // query the first registry value; if this succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath  
  // otherwise the first registry key query failed, so...
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\LucasArts\Star Wars Battlefront II\1.0', 'ExePath', InstallPath) then
    Result := InstallPath;

  // return only the path
  Result := ExtractFilePath(Result);
end;