Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to camelCase a String in Pharo?

I'm trying to get from:

'hello how are you today'

to

'helloHowAreYouToday'

And I thought asCapitalizedPhrase asLegalSelector would do the trick, but it doesn't.

What's the proper way to do this?

EDIT:

I think I should clarify my question; I already have a way to transform a string into a camelCase selector:

|aString aCamelCaseString|
aString := aString findTokens: $ .
aCamelCaseString := aString first.
aString allButFirst do: [:each | aCamelCaseString := aCamelCaseString , each capitalized].

I was just wondering whether Pharo has a standard system method to achieve the same :)

like image 913
Bernat Romagosa Avatar asked Dec 17 '22 17:12

Bernat Romagosa


1 Answers

How about this?

| tokens |
tokens := 'this is a selector' findTokens: Character space.
tokens allButFirst
    inject: tokens first
    into: [:selector :token | selector, token capitalized]
like image 142
Frank Shearar Avatar answered Feb 04 '23 21:02

Frank Shearar