|
Pages: [1]
|
 |
|
Author
|
Topic: Using block index as variable suffix (Read 271 times)
|
Stuart
Guest
|
I have a block like this
block: ["abc" "def" "ghi"]
The actual text of the block will contain text I want o search for in a file.
So later I am trying to search for those block elements one after the other as follows having read a file into "lines":
foreach line lines [ if find line pick block 1 [count1: count1 + 1] if find line pick block 2 [count2: count2 + 1] if find line pick block 3 [count3: count3 + 1] ]
Instead of having to type in each line seperately is there a way I can do a foreach on the elements of block and then use the index number to append to the 'count' variable so it is all nicely packaged in one line?
Thanks for the assistance.
Stuart
|
|
|
|
|
Logged
|
|
|
|
|
CarlRead
|
Something like this should do the job... REBOL []
block: ["abc" "def" "ghi"] counts: array/initial length? block 0
lines: [ "aaa def bbb abc" "sss ghi aaa abc ghi" "fff ddd" "ghi abc def abc" ]
foreach line lines [ repeat num length? block [ ln: line while [not none? ln][ if ln: find/tail ln block/:num [poke counts num counts/:num + 1] ] ] ] probe counts Looking at your method, I don't think it'd handle cases where the same text is repeated more than once in a line. This is why I have the search in a WHILE loop, it continuing the search if the text is found. Hope this helps.
|
|
|
|
|
Logged
|
- Carl Read
|
|
|
Stuart
Guest
|
Thanks Carl, that is a great help.
Stuart
|
|
|
|
|
Logged
|
|
|
|
|
|
Pages: [1]
|
|
|
 |