Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex: Capitalize words in string?

I am trying to do the equivalent of PHP's ucwords() in Flex. I dont want the whole string in uppercase just the first letter of each word. Does anyone know a way?

Thanks!

like image 486
JD Isaacks Avatar asked Jul 17 '26 00:07

JD Isaacks


2 Answers

Try

str.replace(/\b./g,function(m){return String(m).toUpperCase()});

explanation:

the regex /\b./g matches a word boundary followed by any character. All matches will be passed to the anonymous function defined in second parameter of replace method. The function returns the match capitalized.

like image 169
Rafael Avatar answered Jul 22 '26 14:07

Rafael


This is the same as Rafael's answer but with no warnings :)

str.replace(/\b./g,function(...m):String{return m[0].toUpperCase()});
like image 40
JD Isaacks Avatar answered Jul 22 '26 14:07

JD Isaacks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!