Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Tmap and string contains

Hi,

I have a column which contains text string (IDs). There is some logic in our text strings which I would like to use for mapping purposes.
The IDs can be like H123A, H123B or H123C. I am looking to map the data to different columns based on the last character of the text string (A,B or C).

 

For Example:

If ID is H123A it should go to Column1.

If ID is H123B it should go to Column2.

IF ID is H123C then it should go to Column3.

 

Can anyone please help me out on this?


Thanks in advance.

Kind Regards,
Arjun 

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

try this it will work as per your requirement

row1.Source.toLowerCase().contains("a") ?  row1.Source : ""  at column1 on tMap

row1.Source.toLowerCase().contains("b") ?  row1.Source : ""  at column2 on tMap

row1.Source.toLowerCase().contains("c") ? row1.Source : ""at column3 on tMap

 

By assuming we only get either a or b or c not a and b or b and c both at a time in a string.

at the end of function i written string with no spaces.

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Hello @arjunvigneshwar 

am assuming you have 3 columns in the output side in tMap

row1.Source.toLowerCase().contains("ID") ? "H123A" : row1.Source  at column1 on tMap

row1.Source.toLowerCase().contains("ID") ? "H123B" : row1.Source  at column2 on tMap

row1.Source.toLowerCase().contains("ID") ? "H123C" : row1.Source  at column3 on tMap

 

Please write in all three columns, i just written lower case to avoid some case, some id may not be in Caps

Anonymous
Not applicable
Author

@ksingh 

 

Hi Manish,

 

Will the below commands work when ever the fields contains the string "A" "B" or "C".

If the string contains the alphabet A it should go t Column 1, if B then to Column2 or else to column 3.

 

Thanks in advance.

Kind Regards,

Arjun Rathinam

fdenis
Master

add this on the output filter of a tmap row.IDs.substring(4).equals("A")
Anonymous
Not applicable
Author

Hi Francois,

 

It is not necessary that the A or B or C should be the 5 character of the string. It can be anywhere. Basically if the string contains the Aplhabet A it should be in column1 or if it contains B anywhere then it should be in Column2 or else it should be in Column3.

 

But when I tried your solution I am getting the attached error.

 

Thanks in advance.

Kind Regards,

Arjun


Error.PNG
Anonymous
Not applicable
Author

@arjunvigneshwar  did you tried the function i mentioned earlier?

Anonymous
Not applicable
Author

@ksingh  Yes, I did. I am getting the attached output.

 

In am currently getting the output which highlighted in yellow. But I am expecting the output to be like the one highlighted in green.

 

PFA,.. 

 

Kind Regards,

Arjun


Output.PNG
Anonymous
Not applicable
Author

try this it will work as per your requirement

row1.Source.toLowerCase().contains("a") ?  row1.Source : ""  at column1 on tMap

row1.Source.toLowerCase().contains("b") ?  row1.Source : ""  at column2 on tMap

row1.Source.toLowerCase().contains("c") ? row1.Source : ""at column3 on tMap

 

By assuming we only get either a or b or c not a and b or b and c both at a time in a string.

at the end of function i written string with no spaces.

Anonymous
Not applicable
Author

Yes, this works perfect! 

 

Thanks a lot.

Kind Regards,

Arjun

Anonymous
Not applicable
Author

@arjunvigneshwar okay thanks, thanks for sharing the example screenshot, so i figured it out easily