findTokens: vs explode:

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

findTokens: vs explode:

Ron Teitelbaum

Hi all,

 

Earlier we discussed a replacement for my explode method.  findTokens: was suggested but

 

'        version         [0]  EXPLICIT Version DEFAULT v1,' findTokens: ‘EXPLICIT’  =

an OrderedCollection('        version         [0]  ' ' Version D' 'FAU' ' v1,')

 

but

 

'        version         [0]  EXPLICIT Version DEFAULT v1,' explode: ‘EXPLICIT’ =

an OrderedCollection('        version         [0]  ' ' Version DEFAULT v1,')

 

I can see that findTokens: removes all instances of each character.  Which is not what I’m looking for.

 

Does anyone have any other suggestions?

 

Ron Teitelbaum



Reply | Threaded
Open this post in threaded view
|

Re: findTokens: vs explode:

Edgar J. De Cleene
Re: findTokens: vs explode: Ron Teitelbaum puso en su mail :

Hi all,
 
Earlier we discussed a replacement for my explode method.  findTokens: was suggested but
 
'       version         [0]  EXPLICIT Version DEFAULT v1,' findTokens: ‘EXPLICIT’  =
an OrderedCollection('       version         [0]  ' ' Version D' 'FAU' ' v1,')
 
but
 
'       version         [0]  EXPLICIT Version DEFAULT v1,' explode: ‘EXPLICIT’ =
an OrderedCollection('       version         [0]  ' ' Version DEFAULT v1,')
 
I can see that findTokens: removes all instances of each character.  Which is not what I’m looking for.
 
Does anyone have any other suggestions?
 
Ron Teitelbaum

Ron:
Hope this helps, sure someone could do better

In String, accesing category

explode: aString
    | pos tokens |
    tokens := OrderedCollection new.
    pos := self findString: aString startingAt: 1.
    tokens
        add: (self copyFrom: 1 to: pos - 1).
    pos := pos + aString size.
    tokens
        add: (self copyFrom: pos to: self size).
    ^ tokens

'       version         [0]  EXPLICIT Version DEFAULT v1,' explode: 'EXPLICIT' an OrderedCollection('       version         [0]  ' ' Version DEFAULT v1,')

I note what copy from yours and paste again in Squeak the delimiters of EXPLICIT was different to single quote

Edgar


Reply | Threaded
Open this post in threaded view
|

Re: findTokens: vs explode:

Göran Krampe
In reply to this post by Ron Teitelbaum
"Ron Teitelbaum" <[hidden email]> wrote:
> Hi all,
>
> Earlier we discussed a replacement for my explode method.  findTokens: was
> suggested but
>
>  '        version         [0]  EXPLICIT Version DEFAULT v1,' findTokens: 'EXPLICIT'  =
>
> an OrderedCollection('        version         [0]  ' ' Version D' 'FAU' 'v1,')

What about:

'¾¾¾¾¾¾¾ version¾¾¾¾¾¾¾¾ [0]¾ EXPLICIT Version DEFAULT v1,'
findBetweenSubStrs: {'EXPLICIT'}

an OrderedCollection('¾¾¾¾¾¾¾ version¾¾¾¾¾¾¾¾ [0]¾ ' ' Version DEFAULT
v1,')

regards, Göran