You are not logged in.
Hi Denis,
I wanted to use ReplaceRegEx() with values from an array, but stuck on the right syntax:
sLine := aLineArray[Index];
//sLine = 'feat:featuring:false:false'
aPartS := SubMatchesRegEx(sLine, '(.+):(.+):(.+):(.+)', FALSE);
// What is here the right syntax to use?
//ReplaceRegEx(const Input, wsFind, wsReplace, bCaseSensitive, bUseSubstitution $1,$2...): WideString;
TempName := ReplaceRegEx(TempName, '''+aPartS[0]+''', #44+aPartS[1]+#44, aPartS[2], aPartS[3]);
I always get "Pascal Script Compile: [Line 50] Error: Type mismatch"
TIA
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
It's because of the two Boolean arguments, there are no Vars expected / allowed:
Works:
TempName := ReplaceRegEx(TempName, aPartS[0], aPartS[1], false, false);
- - -
Don't work:
TempName := ReplaceRegEx(TempName, aPartS[0], aPartS[1], aPartS[2], aPartS[3]);
sP3 := false;
sP3 := 'false';
sP4 := aPartS[3];
TempName := ReplaceRegEx(TempName, aPartS[0], aPartS[1], sP3, sP4);
- - -
Here is the main part of my MultipleSearchAndReplace.pas script
where I had tried to read the four arguments from text file lines:
arrayLines := FileReadLines('MultiReplaceList.txt');
for Index:=0 to Length(arrayLines)-1 do
begin
strLine := arrayLines[Index];
if strLine <> '' then
begin
if WideCopy(strLine, 1, 1) <> ';' then
begin
arrayLineParts := SubMatchesRegEx(strLine, '(.+):(.+):(.+):(.+)', FALSE);
If (Length(arrayLineParts) = 4)Then
TempName := ReplaceRegEx(TempName, arrayLineParts[0],arrayLineParts[1], false,false);
end;
end;
Index := Index + 1;
end;
MultiReplaceList.txt
mp3:MP4:false:false
;Old2:new2:false:false
;Old 3:New 3:false:false
e:X:false:false
a:Q:false:false
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
The signature of ReplaceRegEx function is as follows:
function ReplaceRegEx(const Input, Find, Replace: WideString; const CaseSensitive, UseSubstitution: Boolean): WideString;
Pascal Script engine does not allow optional parameters or overloaded functions, unfortunately.
Are you experiencing any issues?
Offline
Thanks for your support.
...
Are you experiencing any issues?
You ask if I have a problem?
Only that I tried to set the last two parameters dynamically, read from a text file.
But as you already wrote, that is not possible.
OK, fine. I just tried it and if it is not possible I have to find another way.
For example next I try
IF MyArray[3] = false then
execute "RegEx(x,x,x, false
Else If
execute "RegEx(x,x,x, true
or smtg like this. ...next week,...in my launch break...
Read the *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)
Offline
Don't work:
TempName := ReplaceRegEx(TempName, aPartS[0], aPartS[1], aPartS[2], aPartS[3]);
You can set the last 2 parameters dynamically, through variables, but variables must be of Boolean type. Strings do not get converted to Boolean type automatically, you must do the conversion.
For example:
TempName := ReplaceRegEx(TempName, aPartS[0], aPartS[1], ConvertStrToBool(aPartS[2]), ConvertStrToBool(aPartS[3]));
Where ConvertStrToBool function can be something like this:
function ConvertStrToBool(const Value: String): Boolean;
begin
if (Value = 'true') or (Value = '1') then
Result := True
else
Result := False;
end;
Offline