Multiple dashes, extracting last 3 numbers.

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
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
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Multiple dashes, extracting last 3 numbers.

Post by zirjeo » Tue Nov 08, 2016 4:30 am

Windows 10, IE 11, VERSION BUILD=11.5.498.2403

Extracted the text....

2637-027-017

I'm trying to isolate the last 3 numbers after the 2nd dash strictly using the dashes because the numbers will always change. I tried the below but I keep getting 027 instead of 017

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); z=y[1].split('-'); z[1];")
Even if I just try

Code: Select all

SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[1];")
It still only picks up 027, would think it would pick up 027-017. It must not like the duplicate dashes. Any ideas?
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Multiple dashes, extracting last 3 numbers.

Post by chivracq » Tue Nov 08, 2016 1:55 pm

zirjeo wrote:

Code: Select all

Windows 10, 
IE 11, 
VERSION BUILD=11.5.498.2403
Extracted the text....

2637-027-017

I'm trying to isolate the last 3 numbers after the 2nd dash strictly using the dashes because the numbers will always change. I tried the below but I keep getting 027 instead of 017

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); z=y[1].split('-'); z[1];")
Even if I just try

Code: Select all

SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[1];")
It still only picks up 027, would think it would pick up 027-017. It must not like the duplicate dashes. Any ideas?
Yep normal, y[0] returns the first part of the 'split()' (=> "2637"), y[1] returns the second part (=> "027") and y[2] returns the third part (=> "017").
=> What you want is simply:

Code: Select all

SET !VAR2 EVAL("var s='{{!EXTRACT}}'; var x,y; y=s.split('-'); y[2];")
Other Solution would be to use 'subStr('-3')', like I had mentioned in some previous Thread of yours where you didn't follow up anymore / which you didn't finish neatly btw...! :shock:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Multiple dashes, extracting last 3 numbers.

Post by zirjeo » Tue Nov 08, 2016 4:01 pm

Thanks that works even though it doesn't quite make sense to me, I don't see how there can be a 3rd part of a split seeing split means to split something in 2. But it works.

The old post I didn't respond on because I had no solution. No idea how to split out 123 out of 12345678.
chivracq
Posts: 9004
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Multiple dashes, extracting last 3 numbers.

Post by chivracq » Tue Nov 08, 2016 5:08 pm

zirjeo wrote:Thanks that works even though it doesn't quite make sense to me, I don't see how there can be a 3rd part of a split seeing split means to split something in 2. But it works.
Well, you have 2 Dashes in your String, then splitting your String on the Dash produces 3 parts.
If you had 3 Dashes, splitting your String on the Dash would produce 4 parts... Etc...
zirjeo wrote:The old post I didn't respond on because I had no solution. No idea how to split out 123 out of 12345678.
Hum, then you should have followed up anyway and mentioned it, I normally stop helping Users if they don't "use the Forum a bit correctly", and following up on all their Threads (and finishing them "neatly" and useful as well for other Users searching the Forum with a similar Qt/Case) is one of my "Criteria"... :idea:

But you would find the Solution (well, "a" Solution, because there are at least half a dozen ways to do what you want...) very easily if you read a bit the Documentation on all the JavaScript Functions I mentioned in that other Thread, it's really very basic Level with thousands of Examples on Internet and even our Forum..., and again, 'subStr()' would do the job directly like in this current Thread...

The only a little bit confusing thing that I find myself with all those JavaScript Functions for String Manipulation, or at least not very-very logical, is that the Index for all Chars in a String always starts at 0, Char_at_Index=0 = 1st Char, Char_at_Index=1 = 2nd Char, etc..., same thing for Arrays like for 'split()'. And I'm not completely sure about the "always", I think I remember there are a few Exceptions...! :?
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Multiple dashes, extracting last 3 numbers.

Post by zirjeo » Tue Nov 08, 2016 6:28 pm

Ok I will look into it, when/if I figure it out ill respond to other post. Thanks
Post Reply