SHARE:

Author: Posted on January 27, 2013 at 10:05 pm
Flex 3, Flex 3
SCRIPTS
0

Flex 3: First Character of String to Upper

Just a quick post which provides an example and a usable function that will allow you to make the first character of a string to upper case using Flex 3.

The code below is well commented and is very self explanatory. From this example you will also learn how to make an entire string upper case and also how to find a particular point within a string.

I hope this is useful, please let us know if you can improve this code or have used it somewhere interested.

private function firstCharToUpper(string:String):String {
	//Ensure that the entire string is in lower case to start with
	var string:String = string.toLowerCase();
	//Get the first letter of the string and make it upper case, then store in a variable
	var firstLetter:String = string.charAt(0).toUpperCase();
	//Get the rest of the string and store in another variable
	var restWord:String = string.substr (1, string.length);
	//Combine both the first letter and rest of the word together
	string = firstLetter + restWord;
	//Return the string
	return string;
}
  • /li>
Please contribute and leave a comment
Post Comment

  • REVIEWS

  • No categories have been added yet

TABLE OF CONTENTS