User Guide

Converting strings between uppercase and lowercase 219
function usdToEuro(matchedSubstring:String,
capturedMatch1:String,
index:int,
str:String):String
{
var usd:String = capturedMatch1;
usd = usd.replace(",", "");
var exchangeRate:Number = 0.853690;
var euro:Number = usd * exchangeRate;
const euroSymbol:String = String.fromCharCode(8364);
return euro.toFixed(2) + " " + euroSymbol;
}
When you use a function as the second parameter of the replace() method, the following
arguments are passed to the function:
The matching portion of the string.
Any capturing parenthetical group matches. The number of arguments passed this way
will vary depending on the number of parenthetical matches. You can determine the
number of parenthetical matches by checking
arguments.length - 3 within the
function code.
The index position in the string where the match begins.
The complete string.
Converting strings between uppercase
and lowercase
As the following example shows, the toLowerCase() method and the toUpperCase()
method convert alphabetical characters in the string to lowercase and uppercase, respectively:
var str:String = "Dr. Bob Roberts, #9."
trace(str.toLowerCase());
// dr. bob roberts, #9.
trace(str.toUpperCase());
// DR. BOB ROBERTS, #9.
After these methods are executed, the source string remains unchanged. To transform the
source string, use the following code:
str = str.toUpperCase();
These methods work with extended characters, not simply a–z and A–Z:
var str:String = "José Barça";
trace(str.toUpperCase(), str.toLowerCase()); // JOSÉ BARÇA josé barça