
Contributor III
2015-01-16
05:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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
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
824 Views
1 Solution
Accepted Solutions

Contributor III
2015-01-20
05:05 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
824 Views
5 Replies

Anonymous
Not applicable
2015-01-17
12:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
824 Views

Contributor III
2015-01-20
05:05 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
825 Views

Specialist III
2015-04-17
04:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Hleyes.
Could you share your solution for future generations?
Thanks.
BR, one-in-need
Could you share your solution for future generations?
Thanks.
BR, one-in-need
824 Views

Anonymous
Not applicable
2015-04-17
04:43 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
824 Views

Contributor
2019-03-12
08:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
please write the code for middle name
remaining two are working last and first
824 Views
