[Jprogramming] locating indices of string in list of strings

Don Kelly dhky at shaw.ca
Thu Aug 28 21:52:44 UTC 2014


to complete it

<: ((+./"1 'cd' E."1 arr)*>:i.# arr)-.0

1 3 5 7 9

<: ((+./"1 'ab' E."1 arr)*>:i.# arr)-.0

0 4 8


1 5 9 0 4 8{arr

cd

cd

cd

ab

ab

ab
now make it tacit.


Don Kelly


On 28/08/2014 5:44 AM, Rob Hodgkinson wrote:
> Joe, hope this helps to clarify… Bill was suggesting this…/Rob
>
>     arr=:10 $ > ;: 'ab cd yyy jcd'
>     arr
> ab
> cd
> yyy
> jcd
> ab
> cd
> yyy
> jcd
> ab
> cd
>     'cd' E."1 arr
> 0 0 0
> 1 0 0
> 0 0 0
> 0 1 0
> 0 0 0
> 1 0 0
> 0 0 0
> 0 1 0
> 0 0 0
> 1 0 0
>     +./"1 'cd' E."1 arr
> 0 1 0 1 0 1 0 1 0 1
>
>
> On 28 Aug 2014, at 10:12 pm, Joe Bogner <joebogner at gmail.com> wrote:
>
>> Tracy - symbols are a good way to go. Thanks for reminding me of them.
>>
>> Raul - that's what I was missing... I needed to use e. with the same
>> shape: eg.  arr e. (1 3 $ 'ab ')... Thank you.  Your examples are nice
>> and generic and faster than -:"1
>>
>> ...
>> bill - Not sure what to do with E.
>>
>> Bjorn - 'ab' I. arr doesn't seem to help either... I was hoping for a
>> mask of 0 1 0 1 for whether it was found or the indices
>>
>> On Thu, Aug 28, 2014 at 7:56 AM, Björn Helgason <gosinn at gmail.com> wrote:
>>> 'ab' I. arr
>>>
>>> __-------------------_
>>> https://groups.google.com/forum/m/#!forum/havaogskulamal
>>> On 28 Aug 2014 10:58, "Joe Bogner" <joebogner at gmail.com> wrote:
>>>
>>>> Apologies for the extremely basic question, but I am struggling with
>>>> this after searching NuVoc and the dictionary.
>>>>
>>>> How do I locate all the indices of 'ab' in arr?
>>>>
>>>> arr=:10 $ > ;: 'ab cd yyy'
>>>>
>>>> surely this isn't the best way:
>>>>
>>>> ] (3 = +/"1 'ab' i. arr) # arr
>>>> ab
>>>> ab
>>>> ab
>>>> ab
>>>>
>>>>
>>>> I have been primarily dealing with boxed strings up to this point,
>>>> which seemed easier since it was locating an atom in a list, not a
>>>> list in a table (practicing my vocabulary here... I might be wrong
>>>> though)
>>>>
>>>>
>>>> Thanks,
>>>> Joe
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



More information about the Programming mailing list