E
E
Edward Treit2021-10-06 18:54:03
Pascal
Edward Treit, 2021-10-06 18:54:03

How to replace \\ with \?

Greetings. There is a pascal script:

{
  Replace substring in model file names of records that have models.
  If model already contains sReplaceWith part, it will be skipped.
}
unit ReplaceLtex;

const
  sReplaceWhat = '\any\'; // replace what substring
  sReplaceWith = '\some\'; // replace with substring
  sModelElements = 'Model\MODL,Male world model\MOD2,Female world model\MOD3,Female biped model\MOD3,Female world model\MOD4,Male 1st Person\MOD4,Female 1st Person\MOD5';

var
  slModel: TStringList;
 
function Initialize: integer;
begin
  slModel := TStringList.Create;
  slModel.Delimiter := ',';
  slModel.StrictDelimiter := True;
  slModel.DelimitedText := sModelElements;
end;  

function Process(e: IInterface): integer;
var
  i: integer;
begin
  for i := 0 to slModel.Count - 1 do
    // skip models that already contain sReplaceWith, comment this line out to replace everywhere
    if Pos(sReplaceWith, GetElementEditValues(e, slModel[i])) = 0 then
      SetElementEditValues(e, slModel[i], StringReplace(GetElementEditValues(e, slModel[i]), sReplaceWhat, sReplaceWith, [rfIgnoreCase]));
end;

function Finalize: integer;
begin
  slModel.Free;
end;  

end.

I'm trying to replace \\ with \ with it, but it doesn't work. In principle, nothing can be replaced with \. But I can easily replace anything with \\.
Is there a way to escape the backslash?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HemulGM, 2021-10-06
@HemulGM

615ddcffea908318225568.png
615ddd6fb89d0566869083.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question