[英]How to replace single backslash with double backslashes in paths using Delphi?
这是我的代码:
var
Form1: TForm1;
///--- Değişkenler ---///
//-- String --//
str_ÖgeninKonumu: String;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
if(ParamCount <> 1) then begin
ExitProcess(0);
end else begin
str_ÖgeninKonumu := ParamStr(1);
StringReplace(str_ÖgeninKonumu, '\\', '\\\\', [rfReplaceAll]);
str_ÖgeninKonumu := '"' + str_ÖgeninKonumu + '"';
Clipboard.AsText := str_ÖgeninKonumu;
ExitProcess(0);
end;
end;
当我右键单击任何文件/文件夹并选择“发送到”选项时,此应用程序会将该文件/文件夹的路径作为第一个参数并复制到剪贴板。
但我想在路径中用\\ (double backslashes)
替换\ (single backslash)
。
我怎样才能做到这一点?
好的,由于StringReplace
是一个函数,这里是更正的代码(顺便说一下,Delphi 不像 C 语言那样工作。这意味着,反斜杠不应该在 Delphi 中转义。):
var
Form1: TForm1;
///--- Değişkenler ---///
//-- String --//
str_ÖgeninKonumu: String;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
if(ParamCount <> 1) then begin
ExitProcess(0);
end else begin
str_ÖgeninKonumu := ParamStr(1);
str_ÖgeninKonumu := StringReplace(str_ÖgeninKonumu, '\', '\\', [rfReplaceAll]);
str_ÖgeninKonumu := '"' + str_ÖgeninKonumu + '"';
Clipboard.AsText := str_ÖgeninKonumu;
ExitProcess(0);
end;
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.