Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have an sql file which is the source file and a table which is the destination table. The data of the source file is something like:
"Refer to mobile# 014-289" and what I only need to load from the source file to the customer mobile number table is only the number, I should remove this *Refer to mobile#*. Is there anyway to do that using the tmap expression? What is the right syntax/code I should use and it should be done on all the rows, so meaning not only 1 row, there's a row that don't have that *Refer to mobile#* and only mobile number, which is not a problem as there's no modification or anything that is needed.
The tmap looks like the attachment.
Thank you in advance for any suggestion or help.
Hi,
Please use the below code snippet in the tmap and you can parse the telephone number after #. The screen shot of the tmap is as below.
The code to be used to parse the value is as below. Please change the name of column from test_ip to the column name of your choice.
Relational.ISNULL(row1.test_ip)? row1.test_ip: (row1.test_ip.indexOf('#')<0? row1.test_ip : row1.test_ip.substring(row1.test_ip.indexOf("#") + 2) )
If the answer has helped you to resolve the problem, could you please mark the topic as resolved? Kudos are also welcome 🙂
Warm Regards,
Nikhil Thampi
Hi,
Please use the below code snippet in the tmap and you can parse the telephone number after #. The screen shot of the tmap is as below.
The code to be used to parse the value is as below. Please change the name of column from test_ip to the column name of your choice.
Relational.ISNULL(row1.test_ip)? row1.test_ip: (row1.test_ip.indexOf('#')<0? row1.test_ip : row1.test_ip.substring(row1.test_ip.indexOf("#") + 2) )
If the answer has helped you to resolve the problem, could you please mark the topic as resolved? Kudos are also welcome 🙂
Warm Regards,
Nikhil Thampi
Yeah, the solution is 100% perfect. Thank you @nthampi
But, I forgot to include that I need to remove the - as well, I'm thinking to use another expression which should be like this?
Relational.ISNULL(row1.test_ip)? row1.test_ip: (row1.test_ip.indexOf('#')<0? row1.test_ip : row1.test_ip.substring(row1.test_ip.indexOf("#") + 2) );
row2.test_ip.replaceAll("\\D", "")
Is my approach right?
Hi,
You can do it multiple ways in Talend. You can use the current output of current tmap (ie the phone number with hyphen) as the input for another tmap where you can remove the hyphen with a java replace function.
I would suggest you to try it once as an assignment for yourself to strengthen the learning you have achieved till this point.
But if you are stuck at some point, we are always there to help you 🙂
Warm Regards,
Nikhil Thampi
Hi Ram,
Below logic has helped me to parse the data.
The logic to be used is:-
Alpha -> row1.data.replaceAll("\\P{L}+", "") Numeric -> row1.data.replaceAll("[\\D.]", "")
If the answer has helped you, could you please mark the topic as resolved? Kudos are also welcome 🙂
Warm Regards,
Nikhil Thampi