String operations

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

String operations

Torsten Bergmann
Peter Uhnák wrote:
>am I really blind, or is there no way to do something like
>'BormParticipant' removePrefix: 'Borm' "-> 'Participant'"

what about:

   'BormParticipant' allButFirst: 'Borm' size    


-> 'Participant'

Bye
T.

Reply | Threaded
Open this post in threaded view
|

Re: String operations

Martin Bähr
Excerpts from Torsten Bergmann's message of 2015-04-06 18:24:01 +0200:
> Peter Uhnák wrote:
> >am I really blind, or is there no way to do something like
> >'BormParticipant' removePrefix: 'Borm' "-> 'Participant'"
> what about:
>    'BormParticipant' allButFirst: 'Borm' size    
> -> 'Participant'

that looks like what peter was looking for with 'BormParticipant' copyFrom: 5
'BormParticipant' allButFirst: 4

something like 'BormParticipant' removePrefix: 'Borm' should really fail if the
prefix does not match, thus i would use:

| aString prefix bString |
aString := 'BormParticipant'.
prefix := 'Borm'.
(aString beginsWith: prefix) ifTrue: [ aString allButFirst: prefix size ].

"or to remove a common prefix:"
bString := 'BormMember'.
aString allButFirst: (aString charactersExactlyMatching: bString).

"and related, to find a common prefix:"
aString first: (aString charactersExactlyMatching: bString).

greetings, martin.

--
eKita                   -   the online platform for your entire academic life
--
chief engineer                                                       eKita.co
pike programmer      pike.lysator.liu.se    caudium.net     societyserver.org
secretary                                                      beijinglug.org
mentor                                                           fossasia.org
foresight developer  foresightlinux.org                            realss.com
unix sysadmin
Martin Bähr          working in china        http://societyserver.org/mbaehr/