String Function

I have the following strings:

PRJ_D9_WEST_LE_CLIENT_B
PRJ_D9_WEST_LE_CLIENT_A
PRJ_D9_WEST_LE_CLIENT_C

How do I separate the string to get the following results:

Region | Segment | Client Name
WEST | LE | CLIENT_B
WEST | LE | CLIENT_A
WEST | LE | CLIENT_C

I think it is a combination of Substring and indexOf, but cannot wrap my head around. Thanks, Perri

Hi Perri,

There are multiple ways how to do this. Basically it depends on the rest of your data. At first you might use the split function which can split the string into an array. So for example this function:

myArray = split($in.0.yourString, "_");

will produce the following list (for the first record):

["PRJ", "D9", "WEST", "LE", "CLIENT", "B]

The fields of the aforementioned array may be mapped to output just like this:

$out.0.firstOutField = myArray[2];
$out.0.secondOutField = myArray[3];
$out.0.thirdOutField = concat(myArray[4],"_",myArray[5)];

As I said the actual solution for your case is fully dependent on all your data. Therefore please bear above example as an idea how you can start designing your transformation. The actual transformation design will require you to know the exact format of the data you can receive on input.

You should keep in mind that the second argument of the split function is regular expression, and thus it may contain advanced generic delimiters.

Hope this helps.

Thanks, I tried your code but getting the following error:

11: $out.0.Client = iif(myArray[5]==null,myArray[4],myArray[4] + “_”+ myArray[4]);
^^^
----------------------- CTL2 snippet -----------------------
variable “myArray” (string) :
[PRJ, D9, INTERNAL, TRAINING]

Not all my strings have 4th or 5th element. In this case, how can I check how many elements in an array?

Perri

You may use length() function to get the actual length of the array resulting from the split() function.

Example:

myArray = split($in.0.yourString, "_");
switch(length(myArray)){
case 5:
  //do something
  break;
case 4:
 // do something else
 break;
default:
  // do default handling
}