Hi Mark,

As Don suggested, for this one, the standard library is your friend. :)

   load 'strings'
   ('a';'x') charsub 'abcdefgabcdefg'
xbcdefgxbcdefg
   (LF;',') charsub 'abcd',LF,'asdfasd',LF,'asdfasdf'
abcd,asdfasd,asdfasdf

r/Alex

On Jul 13, 2010, at 8:46 PM, Don Guinn wrote:

> This is one way.
> 
>   y=.'abc',LF,'de',LF,'f'
>   y=LF
> 0 0 0 1 0 0 1 0
>   I.y=LF
> 3 6
>   ','(I.y=LF)}y
> abc,de,f
> 
> Look at 'system\main\strings.ijs' for several tools for manipulating
> strings.
> 
> On Tue, Jul 13, 2010 at 6:31 AM, Mark Needham <[email protected]> wrote:
> 
>> Hey,
>> 
>> I can't work out where in the primer I need to look to work out how to do
>> this so I figured I can post it here and someone can point me to the right
>> place.
>> 
>> I want to replace any new line '\n' characters in a string with a comma
>> ','.
>> 
>> My truly horrific imperative solution looks like this:
>> 
>> replaceNewLines =: 3 : 0
>> i =. 0
>> newY =. ''
>> while. i < # y do.
>> if. i { y = '\' do.
>> if. (i+1) { y = 'n'
>> do.
>> newY =. newY, ','
>> i =. i + 2
>> end.
>> else.
>> newY =. newY, i { y
>> i =. i + 1
>> end.
>> end.
>> newY
>> )
>> 
>> There must be a better way to do this but I can't quite figure it out.
>> 
>> Thanks in advance,
>> Mark
>> ----------------------------------------------------------------------
>> 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