Search code examples
javastringtalendtmap

How to get rid of enter in String


I have a problem in my tMap when I try to do some operations on my string. I have a csv that has Ad_Set_Name that in some rows has more lines in the cell. I use the following:

row4.Ad_Set_Name.contains(" ") ? row4.Ad_Set_Name.substring(0,row4.Ad_Set_Name.indexOf(" ")) : row4.Ad_Set_Name
row4.Ad_Set_Name.contains("\"") ? row4.Ad_Set_Name.substring(row4.Ad_Set_Name.indexOf("\"")+1,row4.Ad_Set_Name.lastIndexOf("\"")) : "null"

I have let's say the Ad_Set_Name "Other vc_7days". So in this case, the first line will give me "Other" and the second one will give me "null". Ad_Set_Name = "Other vc_7days "something" 3rd" the first line will return "Other" and the second "something". But when I have Ad_Set_Name=

"Other

things" I have an error of index like: "StringIndexOutOfBoundsException: String index out of range: -1" Any idea why is that? Thanks a lot!

The error-log is:

Exception in component tMap_1 (facebook_campaigns_amazon_us)
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(Unknown Source)
    at mava2.facebook_campaigns_amazon_us_0_1.facebook_campaigns_amazon_us.tFileInputDelimited_2Process(facebook_campaigns_amazon_us.java:4649)
    at mava2.facebook_campaigns_amazon_us_0_1.facebook_campaigns_amazon_us.tWaitForFile_1Process(facebook_campaigns_amazon_us.java:2322)
    at mava2.facebook_campaigns_amazon_us_0_1.facebook_campaigns_amazon_us.tMysqlConnection_1Process(facebook_campaigns_amazon_us.java:856)
    at mava2.facebook_campaigns_amazon_us_0_1.facebook_campaigns_amazon_us.runJobInTOS(facebook_campaigns_amazon_us.java:5905)
    at mava2.facebook_campaigns_amazon_us_0_1.facebook_campaigns_amazon_us.main(facebook_campaigns_amazon_us.java:5575)

Solution

  • I solved the problem. In the tFileInputDelimited element I didn't checked the CSV Options. Because Talend reads the cell with multiple line with "", I had to have the escape char set on "\"".