How to replaces </BR> for <BR> with EVAL in .js

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

How to replaces </BR> for <BR> with EVAL in .js

Post by frankhack1 » Sat Jan 07, 2017 11:10 pm

Hi, I need to replaces </BR> for <BR> that I'm getting from a text in a .csv file
* I know I can go and change this by just opening the .csv with Notepad++ and replace it all but I have a lot of other situations where I really need to know how to replace this
* I know how to use the replace on EVAL but when the <> or the / are on the equation (in this case </BR>) then the EVAL doesn't work properly with me
* I tried to escape the value 2, 3 or even 4 times but no luck
* I need the solution to go using the EVAL, no other work around such as using a website where I can replace the content (that is my actual approach but I think I can do this with EVAL so I don't need to use this site)

My Config:
Win10 x64
Firefox Palemoon x86 24.6.2
iMacros 8.8.2
Weight = 180pounds
Height = 169cm
Age = 31
:)

Here is my code:

Code: Select all

var macros;
    macros =  "CODE:";

// PARAMETERS
macros += "SET !ERRORIGNORE YES" + "\n";

// DATABASE GENERAL
macros += "SET !DATASOURCE C:\\General.csv" + "\n";
macros += "SET !DATASOURCE_LINE 1" + "\n";

macros += "SET COMENTARIO_INICIO_DESCRIPCION_MESES {{!COL11}}" + "\n";
macros += "SET DESCRIPCION_MESES {{!COL16}}" + "\n";
macros += "SET COMENTARIO_FINAL_DESCRIPCION_MESES {{!COL20}}" + "\n";

// CHANGING </BR> for <BR>
macros += "SET DESCRIPTION {{COMENTARIO_INICIO_DESCRIPCION_MESES}}</BR></BR>{{DESCRIPCION_MESES}}</BR></BR>{{COMENTARIO_FINAL_DESCRIPCION_MESES}}" + "\n";
// --- TESTS ---
// macros += "SET DESCRIPTION EVAL(\"var extr2='{{DESCRIPTION}}'; extr2.replace(/['/BR']/g,'BR');\")" + "\n";
// macros += "SET DESCRIPTION EVAL(\"var extr2='{{DESCRIPTION}}'; extr2.replace(//BR/g,'BR');\")" + "\n";
// macros += "SET DESCRIPTION EVAL(\"var extr2='{{DESCRIPTION}}'; extr2.replace(/</BR>/g,'<BR'>);\")" + "\n";
// macros += "SET DESCRIPTION EVAL(\"var extr2='{{DESCRIPTION}}'; extr2.replace(/[<'/BR>']/g,<'BR>');\")" + "\n";
// macros += "SET DESCRIPCION_-PERIODO- EVAL(\"var extr2='{{DESCRIPCION_-PERIODO-}}'; extr2.replace(/[/]/g,'');\")" + "\n"; // This seems to work as it delete the / but it also affects others parts of the text where there is a / so is not good.
// etc....
// --- TESTS ---
macros += "PROMPT {{DESCRIPCION_MESES}}" + "\n";

iimPlay(macros)
Thanks a lot for the help
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: How to replaces </BR> for <BR> with EVAL in .js

Post by frankhack1 » Wed Jan 11, 2017 1:09 pm

Replying to myself, I used the trim and this did the job, here is the used code:

Code: Select all

var macros;
    macros =  "CODE:";

// PARAMETERS
macros += "SET !ERRORIGNORE YES" + "\n";

// DATABASE GENERAL
macros += "SET !DATASOURCE C:\\General.csv" + "\n";
macros += "SET !DATASOURCE_LINE 1" + "\n";

// VARIABLES
macros += "SET COMENTARIO_INICIO_DESCRIPCION_MESES {{!COL11}}" + "\n";
macros += "SET DESCRIPCION_MESES {{!COL16}}" + "\n";
macros += "SET COMENTARIO_FINAL_DESCRIPCION_MESES {{!COL20}}" + "\n";

// CHANGING </BR> for <BR>
macros += "SET DESCRIPTION_MESES {{COMENTARIO_INICIO_DESCRIPCION_MESES}}</BR></BR>{{DESCRIPCION_MESES}}</BR></BR>{{COMENTARIO_FINAL_DESCRIPCION_MESES}}" + "\n";

// HERE IS WHERE THE MAGIC HAPPENS
macros += "SET DESCRIPTION_MESES EVAL(\"var extr2='{{DESCRIPTION_MESES}'}'; extr2.split('</BR>').join('<BR>').split(' (')[0];\")" + " \n ";

macros += "PROMPT {{{DESCRIPTION_MESES}}" + "\n";

iimPlay(macros)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to replaces </BR> for <BR> with EVAL in .js

Post by chivracq » Wed Jan 11, 2017 2:04 pm

frankhack1 wrote:Replying to myself, I used the trim and this did the job, here is the used code:

Code: Select all

var macros;
    macros =  "CODE:";

// PARAMETERS
macros += "SET !ERRORIGNORE YES" + "\n";

// DATABASE GENERAL
macros += "SET !DATASOURCE C:\\General.csv" + "\n";
macros += "SET !DATASOURCE_LINE 1" + "\n";

// VARIABLES
macros += "SET COMENTARIO_INICIO_DESCRIPCION_MESES {{!COL11}}" + "\n";
macros += "SET DESCRIPCION_MESES {{!COL16}}" + "\n";
macros += "SET COMENTARIO_FINAL_DESCRIPCION_MESES {{!COL20}}" + "\n";

// CHANGING </BR> for <BR>
macros += "SET DESCRIPTION_MESES {{COMENTARIO_INICIO_DESCRIPCION_MESES}}</BR></BR>{{DESCRIPCION_MESES}}</BR></BR>{{COMENTARIO_FINAL_DESCRIPCION_MESES}}" + "\n";

// HERE IS WHERE THE MAGIC HAPPENS
macros += "SET DESCRIPTION_MESES EVAL(\"var extr2='{{DESCRIPTION_MESES}'}'; extr2.split('</BR>').join('<BR>').split(' (')[0];\")" + " \n ";

macros += "PROMPT {{{DESCRIPTION_MESES}}" + "\n";

iimPlay(macros)
Ah-ah...!, nice that you found yourself a Solution and that you share it...! :D

But hum, you are not using 'trim()' but 'split()' + 'join()'... But that's clever, I should have thought of it actually (even if I've never used 'join()' myself...!), that's a good "replacement" for Global 'replace()', I always have difficulties with REGEX and this Global Switch for 'replace()'... :oops:

I actually had a look at your Case a few days ago when you had posted it and I did manage to find some kind of a Solution but it was a bit cumbersome and not "elegant" at all, so I was hoping to find stg better, ah-ah...!, or that some JavaScript Guru would find a better one as well, re-ah-ah...!
Several Statements were working, but the Combination of "<" + "/" + "/g", especially the "/g" was breaking it each time, grrr...!!

The "not elegant" Solution I found that was working:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
TAB T=1

SET !EXTRACT "Word/Line 1</BR>Word/Line 2</BR>Word/Line 3...!"
'PROMPT EXTRACT:<SP>_{{!EXTRACT}}_

'SET Multiline_BR EVAL("var s='{{!EXTRACT}}'; var x,y,z; z=s.replace(/BR/g,'<BR>'); z;") // OK.

SET To_Replace </BR>
'SET Multiline_BR EVAL("var s='{{!EXTRACT}}'; var tr='{{To_Replace}}'; var x,y,z; z=s.replace(tr,'<BR>'); z=z.replace(tr,'<BR>'); z;") // OK.

SET a </BR>
SET b <BR>
SET Multiline_BR EVAL("var s='{{!EXTRACT}}', a='{{a}}', b='{{b}}'; s=s.replace(a,b); s=s.replace(a,b); s;")
PROMPT EXTRACT:<BR>_{{!EXTRACT}}_<BR><BR>Multiline_BR:<BR>_{{Multiline_BR}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10-x64. + v8.9.7, FF49, Win10-x64.)

If you knew that you could expect Max 10x times a "</BR>" in your String, then you would need to repeat 10x times the "s=s.replace(a,b);" part in your 'EVAL()' Statement. I tried to make it as short as possible, but still...! :oops:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
frankhack1
Posts: 83
Joined: Fri Mar 20, 2009 9:12 pm

Re: How to replaces </BR> for <BR> with EVAL in .js

Post by frankhack1 » Wed Jan 11, 2017 3:40 pm

You are right, I didn't use trim but split.

And yes, I also tried the solution where I was duplicating x times the </BR> to replaces this on a text but it was not a good solution.

Hopefully this will help other persons.
Post Reply