[英]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.