Another possibility is:
   NUMBER=: <'NUMBER'
   test=: (<;:'dogs and cats'),(<;:'3 blind mice'),(<;:'alpha'),(<;:'6 plus
100'),(<;:'robot model r2d2')
   ((+./)@('0123456789'&e.)@>)`(,:&NUMBER)}&.> test

Note that the part of test with 'alpha' has to be changed so that it is a
list of word-boxes. You could also set
   test=: ,&.> test
.

This one doesn't have to go through I. to get the indices, so it is
preferred.

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Lettow, Kenneth
Sent: Friday, March 04, 2011 3:49 PM
To: Programming forum
Subject: Re: [Jprogramming] Amending boxed array.

Oops, I copied the wrong indices.

test=: (<;:'dogs and cats'),(<;:'3 blind mice'),(<<'alpha'),(<;:'6 plus
100'),(<;:'robot model r2d2')

]indices=:  I.@; L:1 (+./)@('0123456789'&e.) L:0 test
++-++---+-+
||0||0 2|2|
++-++---+-+

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Lettow, Kenneth
Sent: Friday, March 04, 2011 3:38 PM
To: Programming forum
Subject: [Jprogramming] Amending boxed array.

I have a bunch of strings where each string is boxed and each word in the
string is also boxed.  

The problem is to replace any word that contains a number with a generic
string i.e. "NUMBER".

For example, if the input phrases are: 

test=: (<;:'dogs and cats'),(<;:'3 blind mice'),(<<'alpha'),(<;:'6 plus
100'),(<;:'robot model r2d2')

The output should be:

output=: (<;:'dogs and cats'),(<;:'NUMBER blind
mice'),(<<'alpha'),(<;:'NUMBER plus NUMBER'),(<;:'robot model NUMBER')

I can get the indices of the words to be replaced pretty easily, but I can't
figure out how to use these indices to amend the original phrases.

  ]indices=:  I.@; L:1 (+./)@('0123456789'&e.) L:0 test
+++-+---+-+
|||0|0 2|2|
+++-+---+-+

Any help would be appreciated.


----------------------------------------------------------------------
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

Reply via email to