cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Parsing a string into 2 columns

jdsnap
New Contributor II

Hi, I am trying to parse a list I am getting and putting it into 2 columns.

My value is $email is (xyz@test.com, abc@de.com, 13432@me.com)

What I want to accomplish is parse out $email into two columns in mapper $primaryEmail and $secondaryEmail

I am able design the pipeline to get primary $email.split(โ€˜,โ€™,1). that returns xyz@test.com

By using the search function I am able to determine the index of the first , I was then going to slice it.

$email.search(โ€˜,โ€™) returns 13

how to I encapsulate that in a slice?

Any suggestions ? Thanks in advance.

1 ACCEPTED SOLUTION

Ah, sorry, misunderstood the requirement.

In that case, you could do something like this:

$email.split(',')[0] โ†’ primary
$email.split(',').slice(1).join(',') โ†’ secondary

Hereโ€™s an example pipeline to play around with if itโ€™s helpful.

split-example_2022_04_06.slp (4.9 KB)

View solution in original post

5 REPLIES 5

tlikarish
Employee
Employee

The Split function has an optional limit argument. If you donโ€™t include it, then itโ€™ll split each value. So you should be able to do: $email.split(',')[0] for the value of the primary email and $email.split(',')[1] for the value of a secondary. You may need to handle the case where the email field doesnโ€™t include a comma delimiter and other situations, but thatโ€™s the general approach Iโ€™d take.

jdsnap
New Contributor II

Thanks for the suggestion tlkarish and that wasnโ€™t exactly what I was looking for. Sorry for not being clear.

Using example $email is (xyz@test.com, abc@de.com, 13432@me.com)

I would like to return the following

$primaryEmail - xyz@test.com
$secondaryEmails - abc2de.com, 13432@me.com

Thanks in advance.

You can use this expression given above to get the primary email:

$email.split(',')[0]

And this expression to extract the secondary emails after the primary:
$email.substr($email.indexOf(',') + 1)

keep in mind if there is no secondary email/comma in the given $email string the primary and secondary emails will be the same email.

Ah, sorry, misunderstood the requirement.

In that case, you could do something like this:

$email.split(',')[0] โ†’ primary
$email.split(',').slice(1).join(',') โ†’ secondary

Hereโ€™s an example pipeline to play around with if itโ€™s helpful.

split-example_2022_04_06.slp (4.9 KB)