change the case of a string or perform a case-insensitive comparison in action script
In this post i will help you how to change a string to uppercase,to lower case and also capitalize a first letter of a words.
The "toUpperCase( )" and"toLowerCase( )" methods return new strings in which all the characters are uppercase or lowercase, respectively, without modifying the original string.
you can use toLowerCase( ) or toUpperCase( ) to perform case-insensitive searches within strings
// Displays: flash develop?
trace( ex.toLowerCase( ) );
// Displays: FLASH DEVELOP?
trace( ex.toUpperCase( ) );
// The original string value is unchanged: Flash designer?
trace( example );
//you want to change original string, reassign the return value to it, as follows:
var example:String = example.toLowerCase( );
The following will help you to change the any word for example "DeSigner" into "Designer" to capitalize the first letter of the word.The following is the code in the "main" class
The following is the definition of the method:
The "toUpperCase( )" and"toLowerCase( )" methods return new strings in which all the characters are uppercase or lowercase, respectively, without modifying the original string.
you can use toLowerCase( ) or toUpperCase( ) to perform case-insensitive searches within strings
// Displays: flash develop?
trace( ex.toLowerCase( ) );
// Displays: FLASH DEVELOP?
trace( ex.toUpperCase( ) );
// The original string value is unchanged: Flash designer?
trace( example );
//you want to change original string, reassign the return value to it, as follows:
var example:String = example.toLowerCase( );
public static function initialcap( theword:String ):String {
return theword.charAt( 0 ).toUpperCase( ) + theword.substr( 1 ).toLowerCase( );
}
//The following is an example usage of the method:
var example:String = "DeSigner";
trace( StringUtilities.toInitialCap( example ) ); // Displays: Designer
The "initialcap( )" method converts a string to so-called title case (initial letters capitalized). return theword.charAt( 0 ).toUpperCase( ) + theword.substr( 1 ).toLowerCase( );
}
//The following is an example usage of the method:
var example:String = "DeSigner";
trace( StringUtilities.toInitialCap( example ) ); // Displays: Designer
The following is the definition of the method:
public static function titleCase( originalword:String ):String
{
var words:Array = originalword.split( " " );
for (var i:int = 0; i < words.length; i++)
{
words[i] = initialcap( words[i] );
} return ( words.join( " " ) );
}
//And the following is a sample usage of the method:
var examp:String = " flash developer";
trace( main.titleCase( examp ) );
// Displays: Flash Developer{
var words:Array = originalword.split( " " );
for (var i:int = 0; i < words.length; i++)
{
words[i] = initialcap( words[i] );
} return ( words.join( " " ) );
}
//And the following is a sample usage of the method:
var examp:String = " flash developer";
trace( main.titleCase( examp ) );