How to find the position of a special character in a string

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
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
p3te
Posts: 1
Joined: Thu Apr 14, 2016 5:04 am

How to find the position of a special character in a string

Post by p3te » Thu Apr 14, 2016 5:27 am

I am only new at iMacro - go easy on me :)

I am extracting a block of text which has multiple lines, but I only want the text on the first line.
But how do I use javascript to identify the location of the new line character?

I have tried this:

SET newlinepos EVAL("\"{{!EXTRACT}}\".indexOf(/\\n/);")

The macro runs happily, but it always returns "-1", which I assume means "not found".

Any suggestions?
IrishMacro
Posts: 135
Joined: Wed Nov 03, 2010 12:27 pm

Re: How to find the position of a special character in a str

Post by IrishMacro » Thu Apr 14, 2016 2:02 pm

EVAL can be quite confusing. It's based on regex which isn't easy to use.
As an example, this will go to http://wiki.imacros.net/EVAL and tag "Random wait" and replaces "wait" with a space, leaving just "Random"

URL GOTO=http://wiki.imacros.net/EVAL
TAG POS=1 TYPE=H4 ATTR=TXT:Random<SP>wait EXTRACT=TXT
SET !VAR1 EVAL("var variable=\"{{!EXTRACT}}\"; variable.replace(/wait/g,''); ")
PROMPT {{!VAR1}}

There's probably a better way to do it but this could work for you
Firefox free plugin, last version
Win7
Post Reply