
Anonymous
Not applicable
2015-05-21
02:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[resolved] How to truncate in tMap variable expressions
Hi there,
I want to truncate a string so that it is small enough to fit into an external DB from a Talend csv file output. What I have is the following:
However, I get an index out of range error in the tmap component because I suspect that there are blank cell values which is throwing up null values that causes exceptions when I try to truncate a value.
Anyone know an expression I can write to take care of null values as well as truncate my string to the required size at the same time?
Thanks,
Facoda
I want to truncate a string so that it is small enough to fit into an external DB from a Talend csv file output. What I have is the following:
row1.OOH_Type.substring(0,150)
However, I get an index out of range error in the tmap component because I suspect that there are blank cell values which is throwing up null values that causes exceptions when I try to truncate a value.
Anyone know an expression I can write to take care of null values as well as truncate my string to the required size at the same time?
Thanks,
Facoda
441 Views
1 Solution
Accepted Solutions

Anonymous
Not applicable
2015-05-21
09:12 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not to do with nulls. You cannot have null as part of a String. Null is literally nothing. This is caused by the value you are trying to truncate not being 150 characters long. To get round this you can use something like below...
First we check to make sure the value is not null, then we check to see that the length is greater than 150 chars. If both are true, then we substring to get a 150 char String, otherwise we just return the original value.
row1.OOH_Type!=null && row1.OOH_Type.length()>150 ? row1.OOH_Type.substring(0,150) : row1.OOH_Type
First we check to make sure the value is not null, then we check to see that the length is greater than 150 chars. If both are true, then we substring to get a 150 char String, otherwise we just return the original value.
441 Views
2 Replies

Anonymous
Not applicable
2015-05-21
09:12 PM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not to do with nulls. You cannot have null as part of a String. Null is literally nothing. This is caused by the value you are trying to truncate not being 150 characters long. To get round this you can use something like below...
First we check to make sure the value is not null, then we check to see that the length is greater than 150 chars. If both are true, then we substring to get a 150 char String, otherwise we just return the original value.
row1.OOH_Type!=null && row1.OOH_Type.length()>150 ? row1.OOH_Type.substring(0,150) : row1.OOH_Type
First we check to make sure the value is not null, then we check to see that the length is greater than 150 chars. If both are true, then we substring to get a 150 char String, otherwise we just return the original value.
442 Views

Anonymous
Not applicable
2015-05-22
07:27 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is sweet! Thanks rhall
441 Views
