2 x replace functions in one entry?

Hi there

I am working off a spreadsheet were the person’s gender is noted as either “m” or “f”.

I need this converted into “male”/“female”. If I do the below code, only the bottom entry strangely works (male in this case, female if I swap them).

replace($in.0.Sex,“F”,“Female”)
replace($in.0.Sex,“M”,“Male”)

If however I create two transform components with the exact same entries split, it works fine. So whilst I’ve got this to work, is there is a way of doing this in the one entry so my graph is tidier?

Cheers, Brendan

In this trivial case, I’d use switch statement instead:

switch($in.0.Sex){
	case "f":
	case "F":
		$out.0.Sex = "Female";
		break;
	case "m":
	case "M":
		$out.0.Sex = "Male";
		break;
	default:
		$out.0.Sex = null;
}

More elegant way, where you might have more “translation” could involve SimpleLookup.
Nevertheless, I’m wondering how rest of your code looks like. Because what you describe should not happen.

Hi all,
thank you for the question as well as the answer. Using the ‘switch’ statement is indeed one of the possible options how to deal with such replacement.
If you want to stick to the ‘replace’ statement that you demonstrated in your issue description, you could also use the following piece of CTL code in the Reformat component:

$out.0.Sex = replace(replace($in.0.Sex,"[mM]","Male"),"[fF]","Female");

Note: this example will work in your particular situation with the “Male” and “Female” string, however, it is not generic. There are a handful of more generic approaches such as already mentioned ‘switch’ statement and ‘SimpleLookup’, also ‘if’ statement or some of the other lookups could be used for this purpose in general.