convert string to array

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
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
ledchoi
Posts: 8
Joined: Wed Mar 29, 2017 6:00 pm

convert string to array

Post by ledchoi » Wed Apr 05, 2017 2:47 pm

I want to convert a string="15,16,20" to an array
and splited by "," so array will become
Karray[0]="15"
Karray[1]="16"
Karray[2]="20"
So I can add them to SELECTOR for running EVENTS base the for loop
for(int i=0;Karray.length;i++)
{
EVENT TYPE=CLICK SELECTOR="HTML>BODY>DIV:nth-of-type(9)>DIV>DIV>DIV:nth-of-type(2)>DIV>DIV>DIV>DIV>DIV:nth-of-type(4)>DIV>DIV>DIV>DIV>A:nth-of-type("+Karray+")>SPAN" BUTTON=0
}
Many thanks :D
Last edited by ledchoi on Fri Apr 07, 2017 2:18 pm, edited 5 times in total.
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Show error record when running loop read file csv

Post by chivracq » Wed Apr 05, 2017 4:30 pm

ledchoi wrote:Hello, I have an issue. Codes in my iim file and data in my csv file are very complex. I'm wondering how to show the record that is error when running loop read from .csv so I can fix it. Thank guys!
Hum..., first Post on the Forum but please read the Forum Rules for Required Info to include in your Post when you open a Thread or post for the first time in some existing Thread... I don't react to such "low Quality" Threads otherwise normally... :idea:
=> CIM...! :mrgreen: (Read my Sig..., many Commands are not implemented for all Browsers/Versions...)

(But hum..., second Post actually, I see that you've deleted your previous "HELP ME" Thread, this is what I mean about "low Quality", that's why I had not reacted, a Thread Title needs to be Descriptive without any "Drama", and deleting previous Threads once you've managed to find a Solution instead of sharing that Solution for other Users doesn't work very motivating to want to help you...)

And hum..., the 'iMacros for FF' Sub-Forum is meant for Pb's related to specifically only FF, meaning your Script works fine in iMB/IE/CR or if you are using '.js' Scripts (which you don't mention either...!), => try to select the "correct" Sub-Forum when opening a Thread... (But OK, no need to duplicate...)

>>>

Well, "Codes in my iim file and data in my csv file are very complex." is pretty vague, ah-ah...!, especially if you don't post your Script with the URL of the Site/Page and some Sample Data from your '.CSV' File, tja...! :roll:
"(very) complex" is very vague and subjective, I would think...

There are a few Debug Techniques you can use in iMacros (that I use myself), but pfff..., I'll elaborate a bit once you've mentioned your FCI + given more Details about what you mean by "very complex", + mentioned what you've tried... :idea:
If your Script is so "very complex", you should already know a bit how to debug it, you cannot write "complex" Code without debugging it a bit already, I would think, ah-ah...! :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...
ledchoi
Posts: 8
Joined: Wed Mar 29, 2017 6:00 pm

Re: Show error record when running loop read file csv

Post by ledchoi » Fri Apr 07, 2017 2:04 pm

really sorry for my question and appreciate you for writing a long reply. I'm a newbie. I will ask a specific question. I want to convert a string="15,16,20" to an array
and splited by "," so array will become
Karray[0]="15"
Karray[1]="16"
Karray[2]="20"
So I can add them to SELECTOR for running EVENTS base the for loop
for(int i=0;Karray.length;i++)
{
EVENT TYPE=CLICK SELECTOR="HTML>BODY>DIV:nth-of-type(9)>DIV>DIV>DIV:nth-of-type(2)>DIV>DIV>DIV>DIV>DIV:nth-of-type(4)>DIV>DIV>DIV>DIV>A:nth-of-type("+Karray+")>SPAN" BUTTON=0
}
Many thanks :D
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Show error record when running loop read file csv

Post by chivracq » Fri Apr 07, 2017 5:10 pm

ledchoi wrote:really sorry for my question and appreciate you for writing a long reply. I'm a newbie. I will ask a specific question. I want to convert a string="15,16,20" to an array
and splited by "," so array will become

Code: Select all

Karray[0]="15"
Karray[1]="16"
Karray[2]="20"
So I can add them to SELECTOR for running EVENTS base the for loop

Code: Select all

for(int i=0;Karray.length;i++)
{
EVENT TYPE=CLICK SELECTOR="HTML>BODY>DIV:nth-of-type(9)>DIV>DIV>DIV:nth-of-type(2)>DIV>DIV>DIV>DIV>DIV:nth-of-type(4)>DIV>DIV>DIV>DIV>A:nth-of-type("+[b]Karray[i][/b]+")>SPAN" BUTTON=0
}
Many thanks :D
OK..., that's a complete "Revamp" of your Thread, waf-waf-ah-ah...! (One of the 2 Reasons why I systematically quote all previous Posts when I react in a Thread, my previous Reply would now look completely Off-Topic if I had not quoted your Original Post, ah-ah...!)

The "new" Content doesn't really have any direct "Connection" with your previous "...how to show the record that is error when running loop read from .csv so I can fix it.", you don't even seem to be using a '.CSV' File, if it was a separate Qt, it's usually better to open a separate Thread, but OK, never mind, we go for the "Array" now...!

Yep, interesting Technique, not that "very-extremely complex", takes me a few seconds to find a Solution in 1 Line, but I think I use as well a similar Technique in one of my Scripts, so I guess I had already done some "Thinking" about it...

And hum, you didn't post the URL of your Page, but I would think there is probably a more simple Solution using the 'TAG' Mode which would as well probably be more reliable than your Solution which probably won't work anymore as soon as any Content gets added to the Page and its "DIV>DIV>DIV>..." HTML Structure will change... :idea:

But, hum..., you missed the part in my previous Reply about "CIM", => sorry, but mentioning your FCI is a Required Condition for me to answer/follow up on Threads... :idea:
- (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...
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: convert string to array

Post by chivracq » Thu Apr 13, 2017 3:35 am

OK, last Chance from me I would say, I just see/saw you Online (and I waited for quite a while, in case you would post...):
Last visited: 13 Apr 2017, 03:51
=> Still no Follow-up after 7 days, I was already not too happy about you deleting Threads you managed to solve by yourself instead of sharing your Solution, 1 day to react or you'll get the same Reply from me oops!, and other (Advanced) Users already had plenty of time to answer your Qt (which is fairly basic, again..., takes me a few Seconds each time to find a Solution...), so good luck with them... 8)

But honestly, I don't understand why it's so "complicated" to mention 3 Versions about your Environment... :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...
ledchoi
Posts: 8
Joined: Wed Mar 29, 2017 6:00 pm

Re: convert string to array

Post by ledchoi » Thu Apr 13, 2017 3:59 am

I'm sorry for the delayed response. I'm really happy because you spend your time and still follow my thread. Recently, I'm very busy. I didn't provide URL because you have to be charged to get an account on that website.Please read html codes in file attached.
You see, on the photo attached, when color "Aqua" is chosen, class="swatches__item" will be changed to class="swatches_item swatches__item--active". I tried to edit html codes manually and it's worked. The issue here is the website constantly update the colors available, unavailable and change colors position. So I can't do it on my way that is using EVENTS SELECTOR I showed you. now I have no idea. I have to choose colors automatically from .csv generated from a tool (make by myself).
Attachments
1.jpg
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: convert string to array

Post by chivracq » Thu Apr 13, 2017 7:16 am

ledchoi wrote:I'm sorry for the delayed response. I'm really happy because you spend your time and still follow my thread. Recently, I'm very busy. I didn't provide URL because you have to be charged to get an account on that website.Please read html codes in file attached.
You see, on the photo attached, when color "Aqua" is chosen, class="swatches__item" will be changed to class="swatches_item swatches__item--active". I tried to edit html codes manually and it's worked. The issue here is the website constantly update the colors available, unavailable and change colors position. So I can't do it on my way that is using EVENTS SELECTOR I showed you. now I have no idea. I have to choose colors automatically from .csv generated from a tool (make by myself).
OK, you were quick to reply this time, perfect...

BUT, big problem, and sorry, I'm tired of asking about your Environment with all exact Versions...
=> CIM...! :mrgreen: Pfff, 3rd time I'm asking I think... :roll:

What part didn't you understand in...?:
But honestly, I don't understand why it's so "complicated" to mention 3 Versions about your Environment... :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...
ledchoi
Posts: 8
Joined: Wed Mar 29, 2017 6:00 pm

Re: convert string to array

Post by ledchoi » Thu Apr 13, 2017 8:18 am

Sorry :oops: I misunderstood your request
Win7 (64 bit)
FF 52.0.2
iMacros v8.9.7
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: convert string to array

Post by chivracq » Thu Apr 13, 2017 9:05 am

ledchoi wrote:Sorry :oops: I misunderstood your request

Code: Select all

Win7 (64 bit)
FF 52.0.2
iMacros v8.9.7
Eh beh...!, we finally have your FCI, after more than one week, while this Info belongs to your OP each time you open a Thread or post for the first time in some existing Thread...

OK, back to your Thread now..., but hum, your Thread started about finding some "faulty" Record in your '.CSV', then you changed completely and went about some 'Karray' Array, and now it's about "Aqua Swatches" and "changing colors", I don't get the "Connection" with the previous Formulation about the Array...!? :?

You can open as many Threads as you want if you have several Qt's, as long as you follow up correctly on all of them, well I stop answering anyway if you didn't follow up on some previous (= chronologically) Thread, but asking 3 completely different Qt's in each Post in the same Thread each time you come back to the Forum/Thread is confusing for everybody..., Threads on the Forum are meant as a Qt + an Answer, for you but as well meant for other Users searching the Forum with a similar Qt/Scenario...

The Answer to "Karray[n]" was simply to use '{{!LOOP}}' for 'n' in some 'EVAL()' Statement, but for the rest, you lost me a bit...
=> Post a complete Recap/Summary in one (next) Post like if you were starting the Thread from the beginning, with all Info and Script, about your "convert string to array" Pb as the Thread Title still shouts...! (Well, if that's still a correct Title about your (current) Pb...
Converting a String to an Array is btw done using 'split()' on the common Separator...
Oh yeah, that was the Answer to your "Karray[n]" Qt... => 'split()[n]', well maybe 'n-1'...
- (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...
ledchoi
Posts: 8
Joined: Wed Mar 29, 2017 6:00 pm

Re: convert string to array

Post by ledchoi » Fri Apr 14, 2017 4:21 am

Thank you for your advice. I will open another thread.
chivracq
Posts: 8716
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: convert string to array

Post by chivracq » Fri Apr 14, 2017 5:53 am

ledchoi wrote:Thank you for your advice. I will open another thread.
Yeah, this current Thread is a bit of a "mess" now, => one Thread per Qt, and try to select the correct Sub-Forum, until now all your Qt's belonged to the 'General' Sub-Forum and not to the 'iMacros for FF' Sub-Forum... The 'FF' Sub-Forum is meant for Qt's related to specifically only FF, meaning that you already have a Script that works fine on iMB/IE/CR but fails on FF, or if you are using a '.js' Script as '.js' Scripts are only supported on FF.

And each Thread must be a complete Standalone Thread, with FCI and all Info (Descriptive Thread Title (without any Drama like "Please Help!!?/Urgent!!!/etc...") + FCI + URL + Script + complete Description of you Pb and what you've tried), etc... You can have some "Follow-up" Qt in the same Thread if that Follow-up Qt is directly related to the first one, but normally, it's one Thread per Qt...
- (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...
Post Reply