s =: ' ';'this';'is';'a';'sentence' (<'is') 0} s ┌──┬────┬──┬─┬────────┐ │is│this│is│a│sentence│ └──┴────┴──┴─┴────────┘ 4 ({.,(<'sample'),}.) s ┌─┬────┬──┬─┬──────┬────────┐ │ │this│is│a│sample│sentence│ └─┴────┴──┴─┴──────┴────────┘ 1 }. s ┌────┬──┬─┬────────┐ │this│is│a│sentence│ └────┴──┴─┴────────┘ (2 {. s), 3 }.s ┌─┬────┬─┬────────┐ │ │this│a│sentence│ └─┴────┴─┴────────┘ (<'the') (I. s = <,'a')} s ┌─┬────┬──┬─┬────────┐ │ │this│is│a│sentence│ └─┴────┴──┴─┴────────┘ (<'the') (I. s = <'a')} s ┌─┬────┬──┬───┬────────┐ │ │this│is│the│sentence│ └─┴────┴──┴───┴────────┘ s -. <'is' ┌─┬────┬─┬────────┐ │ │this│a│sentence│ └─┴────┴─┴────────┘
In other words: 1) yes 2) yes 3) yes, but be careful In this case, your s contained five boxes. Four of those boxes where character sequences. One of them was just a character. In the general case, you need to be aware of the distinction between a character (rank 0) and a sequence of characters (rank 1), and you especially need to be aware of the distinction between a character and a sequence of characters of length 1. They're different but seem to be the same. This is analogous to the distinction between 2 and 3 4 5 The first is just a number, the second is a sequence of numbers... And you can have sequences of numbers of length 1, but that's not quite the same thing as the number by itself. -- Raul On Sun, Sep 16, 2012 at 3:30 PM, Emir Ustamujic <emir_...@yahoo.com> wrote: > Hello, > > As I'm often working with boxes of strings I have identified several things > that I would like to do with boxed strings but haven't figured how to do yet > as I'm still learning J. > > [I hope the boxes in the examples don't turn out garbled...] > > > 1. If there is a list of boxed words(strings) how to replace individual items > with another string ? > > For example I have : > ] s =: ' ';'this';'is';'a';'sentence' > ┌─┬────┬──┬─┬────────┐ > │ │ this│ is│a│ sentence│ > └─┴────┴──┴─┴────────┘ > but would like to use something like: 0 boxitemreplace s; 'is' (to replace > the first element which can be a space with 'is) > and get this result : > ┌──┬────┬──┬─┬────────┐ > │is │this │is │a │sentence │ > └──┴────┴──┴─┴────────┘ > or something like 2 boxitemreplace s;' ' (to replace the third element with a > space) > ┌──┬────┬──┬─┬────────┐ > │ │this │ │a │sentence │ > └──┴────┴──┴─┴────────┘ > > 2. Insert and Remove > > For example using the same s =: ' ';'this';'is';'a';'sentence': > would it be possible to somehow insert a word at a specific index so: 4 > inserttobox s;'sample' > would yield > ┌─┬────┬──┬─┬──────┬────────┐ > │ │this │is │a │sample │sentence │ > └─┴────┴──┴─┴──────┴────────┘ > or remove nth item such as 0 removeitemfrombox s;' ' > ┌────┬──┬─┬──────┬────────┐ > │this │is │a │sample │sentence │ > └────┴──┴─┴──────┴────────┘ > > > 3. And consequently would it be also possible to replace all occurences of > one string value within s with another string and remove all occurences of > one string from a boxed list such as s ? > > I more or less know how to do this with regular strings such as s=: 'this is > a sentence' but my problem is when dealing directly with boxed strings and > when they contain spaces. > > > Thanks &Regards, > Emir > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm