[英]How to replace single backslash with double backslashes in paths using Delphi?
Here are my codes:这是我的代码:
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;
When I right click any file/folder and choose "Send to" option, this application gets the path of that file/folder as first parameter and copies to the clipboard.当我右键单击任何文件/文件夹并选择“发送到”选项时,此应用程序会将该文件/文件夹的路径作为第一个参数并复制到剪贴板。
But I want to replace \ (single backslash)
with \\ (double backslashes)
in the path.但我想在路径中用
\\ (double backslashes)
替换\ (single backslash)
。
How can I achieve this?我怎样才能做到这一点?
Ok, since StringReplace
is a function, here are corrected codes (By the way, Delphi does not work like C languages. Which means, backslash should not be escaped in Delphi.):好的,由于
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.