manipulating strings

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

manipulating strings

stepharo
Hi

I have the following problem I want to transform a string into another
while removing a set of characters

     'Uquillas G\'{o}mez'

     ->

     'uquillasgomez'

And I wonder how to do that?

copyWithoutAll:


I was thinking to create a string of the same size and copy only the
valid characters.

Now I do not know how to set the size of the resulting string.

I could use  stream.

Any ideas is welcome.

Stef


Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

stepharo
I did


String
         streamContents: [ :str |
             aString
                 do: [ :aChar |
                     aChar isLetter
                         ifTrue: [ str nextPut: aChar asLowercase ] ] ]


I'm curious about other solution because I was lucky that isLetter exist.

Stef

Le 10/8/16 à 19:48, stepharo a écrit :

> Hi
>
> I have the following problem I want to transform a string into another
> while removing a set of characters
>
>     'Uquillas G\'{o}mez'
>
>     ->
>
>     'uquillasgomez'
>
> And I wonder how to do that?
>
> copyWithoutAll:
>
>
> I was thinking to create a string of the same size and copy only the
> valid characters.
>
> Now I do not know how to set the size of the resulting string.
>
> I could use  stream.
>
> Any ideas is welcome.
>
> Stef
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

Esteban A. Maringolo
Would this work?

'Uquillas G\''{o}mez' onlyLetters asLowercase
Esteban A. Maringolo


2016-08-10 15:00 GMT-03:00 stepharo <[hidden email]>:

> I did
>
>
> String
>         streamContents: [ :str |
>             aString
>                 do: [ :aChar |
>                     aChar isLetter
>                         ifTrue: [ str nextPut: aChar asLowercase ] ] ]
>
>
> I'm curious about other solution because I was lucky that isLetter exist.
>
> Stef
>
> Le 10/8/16 à 19:48, stepharo a écrit :
>
>> Hi
>>
>> I have the following problem I want to transform a string into another
>> while removing a set of characters
>>
>>     'Uquillas G\'{o}mez'
>>
>>     ->
>>
>>     'uquillasgomez'
>>
>> And I wonder how to do that?
>>
>> copyWithoutAll:
>>
>>
>> I was thinking to create a string of the same size and copy only the valid
>> characters.
>>
>> Now I do not know how to set the size of the resulting string.
>>
>> I could use  stream.
>>
>> Any ideas is welcome.
>>
>> Stef
>>
>>
>>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

stepharo
quite nice indeed!


Le 10/8/16 à 20:04, Esteban A. Maringolo a écrit :
> 'Uquillas G\''{o}mez' onlyLetters asLowercase


Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

stepharo
Now I was really wondering how I could copy characters by characters
without relying on a stream to get a string from the correct size at the
end.

In particular copyWithout: and friends only works either with one
subcollection or one elements and I have mulitple elements \ { } '`

Stef



Le 10/8/16 à 22:30, stepharo a écrit :
> quite nice indeed!
>
>
> Le 10/8/16 à 20:04, Esteban A. Maringolo a écrit :
>> 'Uquillas G\''{o}mez' onlyLetters asLowercase
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

webwarrior
Why not use standard collection API?

'Uquillas G\''{o}mez' reject: [ :c | #($\ ${ $} $' $`) includes: c ] thenCollect: #asLowercase
Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

Nicolai Hess-3-2
In reply to this post by stepharo


2016-08-11 7:30 GMT+02:00 stepharo <[hidden email]>:
Now I was really wondering how I could copy characters by characters without relying on a stream to get a string from the correct size at the end.

In particular copyWithout: and friends only works either with one subcollection or one elements and I have mulitple elements \ { } '`

Stef

copyWithoutAll: does not work ?

'Uquillas G\''{o}mez' copyWithoutAll: '\{}''`'   -> 'Uquillas Gomez'

 



Le 10/8/16 à 22:30, stepharo a écrit :

quite nice indeed!


Le 10/8/16 à 20:04, Esteban A. Maringolo a écrit :
'Uquillas G\''{o}mez' onlyLetters asLowercase






Reply | Threaded
Open this post in threaded view
|

Re: manipulating strings

Denis Kudriashov
In reply to this post by webwarrior

2016-08-11 12:45 GMT+02:00 webwarrior <[hidden email]>:
Why not use standard collection API?

'Uquillas G\''{o}mez' reject: [ :c | #($\ ${ $}

There is short version: copyWithoutAll:#($\ ${ $}