[Jprogramming] Replacing part of a string

Alex Rufon alex_rufon at ist-systems.com
Tue Jul 13 21:02:09 HKT 2010


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 <m.h.needham at gmail.com> 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



More information about the Programming mailing list

AltStyle によって変換されたページ (->オリジナル) /