我要取得
  str:='HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot';
最后面的SystemRoot子字符串.
  应该怎么做呢??
  要求SystemRoot有多少个字符事先并不知道.

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      str: String;
    begin
      str:='HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot';
      Showmessage(ExtractFilename(str));
    end;
      

  2.   

    用Rightstr函数。
    rightstr(str,10)
      

  3.   

    str := ExcludeTrailingBackslash(str);
    for I:=length(str) downto 1 do
        if str[I]='\' then
          result := Copy(str,I+1,length(str)-I);
      

  4.   

    use StrUtils
    procedure TForm1.Button1Click(Sender: TObject);
    var
      str: string;
      pos_index: integer;
    begin
      pos_index := 0;
      str:='HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot';
      str := ReverseString(str); //将字符串反序
      str := ReverseString(LeftStr(str, pos('\', str) - 1));
      ShowMessage(str);
    end;
    以上代码调式通过!