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

Reply via email to