
NB. Kernagain and Ritchie in J

NB. Usage ex1_1						(p8)
ex1_1 =: 0 : 0

Hello Universe!
)

NB. Find and replace all occurances of character <f> 
NB. with character <r> in array <y>.
NB.
NB. Usage: fr replace y
NB.
NB. Example:
NB.  '_-' replace1 3 2 $ '_2 6_9'
NB.
replace1 =: 4 : 0
'f r' =. x
($y) $ r ((s=f)# i. #s) } s =. ,y
)

NB. ex1_2 does not apply to J 		(p8)

NB. Usage ex1_3 ''					(p13)
ex1_3 =: 3 : 0
C =. F2C F =. step 0 300 20
t =. '_-' replace1 3j0 8j1": F ,. C
' ', ' F     C',t
)

NB. Usage ex1_4 ''					(p13)
ex1_4 =: 3 : 0
F =. C2F C =. step 0 300 20
t =. '_-' replace1 3j0 8j1": C ,. F
' ', ' C     F',t
)

NB. Usage: ex1_5 ''					(p14)
ex1_5 =: 3 : 0
F =. C2F C =. step 300 0 _20
t =. '_-' replace1 3j0 8j1": C ,. F
' ', ' C     F',t
)

NB. ex1_6 and ex1_7 do not apply.	(p17)

NB. Count blanks, tabs and newlines
NB. Usage ex1_8 'fname'				(p20)
NB.
ex1_8 =: 3 : 0
c=. 9 10 32 { a.	NB. Chars to count: TAB, LF, space
pwd=. 'c:\users\de51225\j64-602-user\temp'
('Changing PWD to ',pwd)(1!:2) 2
1!:44 pwd
s =. 1!:1 < y
+/(#c) ~: c i. s
)

NB. Copy SRC to DEST except eliminate duplicate spaces.
NB. Usage: DEST =: ex1_9 SRC		(p20)
NB.
ex1_9 =: 3 : 0
(1,(}.b) *: }:b=.y=' ')#y

NB. Replace certain chars with escape chars.
NB. Usage: ex1_10 str
NB.
tally1=: 4 : '#>x{y'
find=. 'ABC'	NB. Any list of chars to be replaced
repl=. '\A;\B;\C'
b=. s="_ 0 find

