I have a string that represents the name of an object...
How best can I check whether the string contains a reference to a locale?
AND/OR
How best can I retrieve the reference to the locale from the string?
I suspect that there is probably the facility to do this somewhere in the J
system, but was unable to find it. I've created something that does the job for
now, but would rather use a built in facility if it exists.
isLocRef 'myname_myloc_'
1
getLocRef 'myname_myloc_'
_myloc_
n1=. 'myname'
n2=. 'my_name'
n3=. 'my_n_ame'
n4=. 'myname__'
n5=. 'myname__myloc3'
n6=. 'myname_myloc4_'
n7=. 'myname_myloc5_'
n8=. 'my_name_myloc6_'
n9=. 'my_name__myloc7'
tstnames=: n1;n2;n3;n4;n5;n6;n7;n8;n9
isLocRef &> tstnames
0 0 0 1 1 1 1 1 1
getLocRef &.> tstnames
++++--+--------+--------+--------+--------+--------+
||||__|__myloc3|_myloc4_|_myloc5_|_myloc6_|__myloc7|
++++--+--------+--------+--------+--------+--------+
getLocRef=: 3 : 0
msk=. y = '_'
if. (({: *. 1 < +/) msk) +. 2 e. 2+/\ msk do.
(_2 { I. msk) }. y
else.
''
end.
)
isLocRef=: 0 < [EMAIL PROTECTED]
Or all tacit:
isLocRefT=: [: (({: *. 1 < +/) +. 2&([ e. +/\)) '_' = ]
getLocRefT=: ''"_`(] }.~ _2 { [: I. '_'=])@.isLocRefT
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm