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 my own. Hope this helps some one.

PS: I might have used more variables than required.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//below is the function to create camelString
//needs little cleaning up.
    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;
    }

Github Gist