Reputation: 1977
I need to convert all values in a structure (arguments passed into a function) to uppercase.
I wrote the following method, but rather than replace the argument with the formatted one, it is creating a new key to the arguments struct (e.g. for first loop, it creates a key of '1' with the value of arguments[1], next loop creates a new key of '2' with the value of arguments[2] and so on.
Can anyone suggest how I can change the value of each key in the struct?
The code kind of shows what I am trying to do, but let me know if you need more info.
public function formatValues(){
numArgs = structCount(arguments);
for (i=1; i<=numArgs ; i=i+1){
arguments[i] = Ucase(arguments[i]);
}
return arguments;
}
Upvotes: 1
Views: 92
Reputation: 7519
Try this:
public function formatValues(){
for (var i in arguments){
if( isSimpleValue( arguments[i] ) ){
arguments[i] = ucase( arguments[i] );
}
}
return arguments;
}
writeDump(formatValues(name="moo",city="baa"));
writeDump(formatValues("moo","baa"));
This will work with named arguments and non-named arguments. It also will only modify simple values (strings, numbers, etc) and not complex variables (arrays, structures, objects)
Upvotes: 5
Reputation: 958
Is it because you forgot the parameter?
public function formatValues(arguments){
var numArgs = structCount(arguments);
for (var i=1; i<=numArgs ; i=i+1)
{
arguments[i] = Ucase(arguments[i]);
}
return arguments;
}
Upvotes: 0