Skip to main content
Announcements
Introducing a new Enhanced File Management feature in Qlik Cloud! GET THE DETAILS!
cancel
Showing results for 
Search instead for 
Did you mean: 
HLeyes
Contributor III
Contributor III

[resolved] Splitting A String At The Last Space

I have used Talend variables and expressions in tMap to split a string at the space, as in a normal name field.  That works for most cases, where there is a first and last name.  For example, "Mickey Mouse" can be split into "Mickey" as the First Name, and "Mouse" as the Last Name. 
I would like to know if there is a way to split a string at the last space.  I'd like to be able to take a string such as "John and Mary Jones", and split off the "Jones" part to become the Last Name, and "John and Mary" to be the First Name.
Thanks in advance!
HL
Labels (2)
1 Solution

Accepted Solutions
HLeyes
Contributor III
Contributor III
Author

Hi Shong,
Thanks very much for the code - that did it!  I modified the expression to account for one-word names, and also to TRIM the string.
HL

View solution in original post

5 Replies
Anonymous
Not applicable

Hi 
Search the last index of space, and truncate the string, for example;
tFileInputDelimited--main--tMap--tlogRow
For first name:
row1.name.substring(0,row1.name.lastIndexOf(" "))
For last name:
row1.name.substring(row1.name.lastIndexOf(" ")+1)
Best regards
Shong
HLeyes
Contributor III
Contributor III
Author

Hi Shong,
Thanks very much for the code - that did it!  I modified the expression to account for one-word names, and also to TRIM the string.
HL
_AnonymousUser
Specialist III
Specialist III

Hi Hleyes.
Could you share your solution for future generations?
Thanks.
BR, one-in-need
Anonymous
Not applicable

Hi JamesBrown 
I suggest you to open a new topic for your question and describe it with more information, so you can gain more help from community users. 
Best regards
Shong
palkondatharun
Contributor
Contributor

please write the code for middle name 

remaining two are working last and first