[Jprogramming] Amending boxed array.
Marshall Lochbaum
mlochbaum at raleighcharterhs.org
Sat Mar 5 04:50:54 HKT 2011
You can use amend with gerunds:
indices ((<'NUMBER')"_)`[`]}&.> test
Marshall
-----Original Message-----
From: programming-bounces at jsoftware.com
[mailto:programming-bounces at jsoftware.com] 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
More information about the Programming
mailing list