Friday, 18 June 2010

Text to uppercase in Actionscript 3

When you copy and paste uppercase letters into Flash sometimes it turns the letters into lowercase. I’ve been converting a lot of arbitrary text to uppercase recently, so have come up with a simple function to avoid manually typing each character into uppercase characters. I've used the toUpperCase() method in the String class which basically turns all the characters into uppercase.

var myString:String = "hello ilike2flash";

function turnUpperCase(uppStr:String):String{
    return uppStr.toUpperCase();    

trace(turnUpperCase("hello ilike2flash")); //HELLO ILIKE2FLASH 

If you wish to only turn the first characters in a string to uppercase, you can use the charAt() method to get the first letter and the substring method to get the remaining characters in the string.

var myString:String = "hello ilike2flash";

function firstUpperCase(firUpp:String):String{
    return firUpp.charAt(0).toUpperCase() + firUpp.substring(1,firUpp.length);

trace(firstUpperCase(myString)); //Hello ilike2flash

To reverse the uppercase characters you can use the toLowerCase() method which will convert all the uppercase characters into lowercase.
var myString:String = "SOME UPPERCASE CHARACTER"

trace(myString.toLowerCase()); //some uppercase character  


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP