var str = "actionscript";
function upperCase(str:String) : String {
var firstChar:String = str.substr(0, 1);
var restOfString:String = str.substr(1, str.length);
return firstChar.toUpperCase()+restOfString.toLowerCase();
}
trace(upperCase(str)); //Outputs Actionscript
Welcome to my actionscript snippet library!
Actionscript Snips is a small repository of actionscript code that aims to save developers and designers time when developing a website.
Capitalize First Letter In String
Posted by
admin
on Monday, July 20, 2009
Labels:
Strings
3 comments:
Used this as part of a random phrase generator in an example for a Autoscroll TextArea. http://deanlogic.com/2011/12/autoscroll-textarea/
Thanks.
function firstLetterUpperCase(strData:String):String
{
var strArray:Array = strData.split(' ');
var newArray:Array = [];
for (var str:String in strArray)
{
newArray.push(strArray[str].charAt(0).toUpperCase() + strArray[str].slice(1));
}
return newArray.join(' ');
}
Post a Comment