Flex: Capitalize First Character of a String – CamelCase Function in Flex
2
Comment(s)
I was writing an Air App in Flex 3 and Action Script 3 and came across a situation where I needed to covert some strings to camel case dynamically before binding them to a control, I searched the API for any such function that would let me convert a string to camel case.
On not finding anything, I decided to write one of my own, and I thought I did share it with you guys. Hope this helps some one.
PS: I might have used more variables then required, but will clean it later, you can apply the logic to other scripting/programming languages too.
PPS: If you need help, let me know
//below function to create camelString
private function camelCaseString(inputstr:String):String
{
var loopcount:int;
var returnstr:String = "";
var origStr:String;
loopcount = inputstr.length;
origStr = inputstr;
while(loopcount>0)
{
var lastSpaceIndex:int = origStr.indexOf(" ",0);
if(lastSpaceIndex<0)
{
lastSpaceIndex=origStr.length;
}
var tempstr:String = origStr.substring(0,lastSpaceIndex);
var firstpartStr:String = tempstr.substr(0,1);
var secondpartStr:String = tempstr.substr(1,tempstr.length);
returnstr = returnstr+firstpartStr.toUpperCase() +secondpartStr.toLowerCase()+" ";
origStr = origStr.substring(lastSpaceIndex+1,origStr.length);
loopcount = loopcount - 1;
}
return returnstr;
}
//function to return camel String ends here
Tags: Adobe AIR, AS3, Camel Case Function Flex, Flex
2 Responses to “Flex: Capitalize First Character of a String – CamelCase Function in Flex”
Comment History Slider
May 22, 2010 at 9:42 am
Hi Maramandan,
Your welcome! Glad you found it useful! yeah, I forgot the trim














Every website I design/develop, I follow some essential steps to make your time and investment count. From free consultation to free post-production support. 
Hi,
Thanks Mr. Manoj. I used your function and found it as very useful. I would like to say that it helped me a lot. I found one small glitch though, the function returned some trailing spaces which I trim()med.
maramandan