Search code examples
smalltalkpharo

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 :)


Solution

  • You don't say which version of Pharo you're using, but in the stable 5.0,

    'hello world this is a selector' asCamelCase asValidSelector
    

    yields

    helloWorldThisIsASelector
    

    To get what I'm using run:

    curl get.pharo.org/50+vm | bash