Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
prabuj
Contributor III
Contributor III

How to split prefix from firstname in Talend ?

Dear Team,

@Richard Hall @Shicong Hong @Xiaodi Shi,

I have these 3 requirement.

  1. I have a prefix coming in name. I would like to split the prefix and move to target.
  2. I would like to remove the prefix from name
  3. I would like to include firstname

Sample data

Mr. Prabhakaran

Mr. Kevin

Mrs. Lindsay

Miss. Pinit

Required Result : ( 1st requirement result )

Mr

Mrs

Miss

Required Result : ( 2nd requirement result )

Prabhakaran

Kevin

Lindsay

Pinit

Required Result: (3rd requirement result )

Rajendran Prabhakaran

Prabuj Kevin

Lohan Lindsay

Julaluk Pinit

Thanks in advance. Please share me with me a clear example , it could help everyone who see the post in future as well as me.

Labels (2)
1 Solution

Accepted Solutions
prabuj
Contributor III
Contributor III
Author

Dear Team @Richard Hall​ @Shicong Hong​ @Xiaodi Shi​ 

 

I have figure out the answer, and love to share the code - so it can be useful to others.

 

0695b00000fJqWBAA0.png0695b00000fJqW1AAK.png0695b00000fJqVwAAK.png 

StringHandling.TRIM(row16.Name).split("\\.")[0]  for trimming the prefix.

StringHandling.TRIM(row16.Name).split("\\.")[1]  for removing the prefix from name

StringHandling.TRIM(row16.Name).split("\\.")[1] + " " + row17.Middle_Name  for including first name with middle name.

 

 

NOTES: ( WHEN DEALING WITH DOT )

You need to escape the dot if you want to split on a literal dot:

String extensionRemoved = filename.split("\\.")[0];

Otherwise you are splitting on the regex ., which means "any character".

Note the double backslash needed to create a single backslash in the regex.

 

If You're getting an ArrayIndexOutOfBoundsException because your input string is just a dot, i.e. ".", which is an edge case that produces an empty array when split on dot; split(regex) removes all trailing blanks from the result, but since splitting a dot on a dot leaves only two blanks, after trailing blanks are removed you're left with an empty array.

 

THANKS FOR ALL THE SUPPORT..!

 

View solution in original post

5 Replies
Anonymous
Not applicable

Hello,

If we understand your requirement very well, you are able to achieve your goal Via tExtractDelimitedFields component.

Extracting a delimited string column (sample data)by setting field separator as "." and then concatenating your 2nd requirement result with the real first name in tMap or Uniting them via tUnite component

Best regards

Sabrina

 

 

 

 

Anonymous
Not applicable

Hello,

This is a demo job work flow.

Hope it helps

0695b00000fJqObAAK.pngBest regards

Sabrina

prabuj
Contributor III
Contributor III
Author

Using tExtractDelimitedFields, by using field seperator as "." - it won't collect the result.

 Because the components work with comma, colon : , semicolon; as per the talend guide. How you can do it with dot as a field seperator ?????

 

First name

Mr. Prabhakaranrajendran

 

How you can concatenate within a column, when it don't produce the result. ? If you concatenate , the 2nd part is the fullname with prefix.

 

1st requirement is to split the prefix.

2nd requirement is to remove the prefix from name

3rd is to include firstname before middle name. ( Prabhakaran Kuppusamy Rajendran)

Kuppusamy is the middle name.

0695b00000fJqQ8AAK.png0695b00000fJqPZAA0.png0695b00000fJqPUAA0.png 

 

MY QUERY IS NOT SOLVED. COULD YOU PLEASE HELP OUT (OR) SHOW WHAT YOU HAVE DONE INSIDE TMAP.

prabuj
Contributor III
Contributor III
Author

@Xiaodi Shi​ @Shicong Hong​ @Richard Hall​ 

 

Using tExtractDelimitedFields, by using field seperator as "." - it won't collect the result.

Because the components work with comma, colon : , semicolon; as per the talend guide. How you can do it with dot as a field seperator ?????

 

First name ( COLUMN_NAME )

Mr. Prabhakaranrajendran

 

How you can concatenate within a column, when it don't produce the result. ?

 

1st requirement is to split the prefix.

2nd requirement is to remove the prefix from name

3rd is to include firstname before middle name. ( Prabhakaran Kuppusamy Rajendran)

Kuppusamy is the middle name.

0695b00000fJqQ8AAK.png0695b00000fJqPZAA0.png0695b00000fJqPUAA0.png RESULT FAILED TO SPLIT AS PER YOUR ADVISED.

 

MY QUERY IS NOT SOLVED. COULD YOU PLEASE HELP OUT (OR) SHOW WHAT YOU HAVE DONE INSIDE TMAP. I FIGURE OUT THE WAY FOR THE 1st requirement in another way , at the end I will share the result.

 

I WOULD LIKE TO KNOW FOR 2nd & 3rd REQUIREMENT.

 

Thanks in advance.

prabuj
Contributor III
Contributor III
Author

Dear Team @Richard Hall​ @Shicong Hong​ @Xiaodi Shi​ 

 

I have figure out the answer, and love to share the code - so it can be useful to others.

 

0695b00000fJqWBAA0.png0695b00000fJqW1AAK.png0695b00000fJqVwAAK.png 

StringHandling.TRIM(row16.Name).split("\\.")[0]  for trimming the prefix.

StringHandling.TRIM(row16.Name).split("\\.")[1]  for removing the prefix from name

StringHandling.TRIM(row16.Name).split("\\.")[1] + " " + row17.Middle_Name  for including first name with middle name.

 

 

NOTES: ( WHEN DEALING WITH DOT )

You need to escape the dot if you want to split on a literal dot:

String extensionRemoved = filename.split("\\.")[0];

Otherwise you are splitting on the regex ., which means "any character".

Note the double backslash needed to create a single backslash in the regex.

 

If You're getting an ArrayIndexOutOfBoundsException because your input string is just a dot, i.e. ".", which is an edge case that produces an empty array when split on dot; split(regex) removes all trailing blanks from the result, but since splitting a dot on a dot leaves only two blanks, after trailing blanks are removed you're left with an empty array.

 

THANKS FOR ALL THE SUPPORT..!