#1 2017-05-12 09:29

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

PascalScript syntax: ReplaceRegEx(TempName, MyArray[0],MyArray[1],.)

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" tongue


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

#2 2017-05-12 12:40

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: PascalScript syntax: ReplaceRegEx(TempName, MyArray[0],MyArray[1],.)

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

#3 2017-05-12 14:33

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: PascalScript syntax: ReplaceRegEx(TempName, MyArray[0],MyArray[1],.)

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

#4 2017-05-12 18:59

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: PascalScript syntax: ReplaceRegEx(TempName, MyArray[0],MyArray[1],.)

Thanks for your support.



den4b wrote:

...
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

#5 2017-05-12 20:38

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: PascalScript syntax: ReplaceRegEx(TempName, MyArray[0],MyArray[1],.)

Stefan wrote:

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

Board footer

Powered by FluxBB