<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic StringIndexOutOfBoundsException: String index out of range: 40 how to fix in Talend Studio</title>
    <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251905#M35708</link>
    <description>&lt;P&gt;I have two columns (tmysqloutput) that I will get the value from only one column (tmysqlinput) depends on the condition, when I tried&amp;nbsp; to run with to one column first, everything are working perfectly, but then when I load the expression on the second column, I got this error:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Exception in component tMap_4 (FileExtractAndLoad)&lt;BR /&gt;java.lang.StringIndexOutOfBoundsException: String index out of range: 40&lt;BR /&gt;at java.lang.String.substring(Unknown Source)&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;My expression syntax for the column that throwing that error is:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%TOSL%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("to") + 3),(row5.ADDRESS.indexOf("to") + 10))).replace("-", "").replaceAll("\\D*",""))&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;While the first one is this:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%Refer%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("ABC") + 4),(row5.ADDRESS.indexOf("ABC") + 11))).replace("-", "").replaceAll("\\D*",""))&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Is there any possible way on how ti fix this? And if there's a way, I need to implement it on both expression?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks!&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Nov 2018 14:14:19 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-11-15T14:14:19Z</dc:date>
    <item>
      <title>StringIndexOutOfBoundsException: String index out of range: 40 how to fix</title>
      <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251905#M35708</link>
      <description>&lt;P&gt;I have two columns (tmysqloutput) that I will get the value from only one column (tmysqlinput) depends on the condition, when I tried&amp;nbsp; to run with to one column first, everything are working perfectly, but then when I load the expression on the second column, I got this error:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Exception in component tMap_4 (FileExtractAndLoad)&lt;BR /&gt;java.lang.StringIndexOutOfBoundsException: String index out of range: 40&lt;BR /&gt;at java.lang.String.substring(Unknown Source)&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;My expression syntax for the column that throwing that error is:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%TOSL%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("to") + 3),(row5.ADDRESS.indexOf("to") + 10))).replace("-", "").replaceAll("\\D*",""))&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;While the first one is this:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%Refer%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("ABC") + 4),(row5.ADDRESS.indexOf("ABC") + 11))).replace("-", "").replaceAll("\\D*",""))&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Is there any possible way on how ti fix this? And if there's a way, I need to implement it on both expression?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Thanks!&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 14:14:19 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251905#M35708</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-15T14:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: StringIndexOutOfBoundsException: String index out of range: 40 how to fix</title>
      <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251906#M35709</link>
      <description>In the second expression you need to change row5.ADDRESS.substring(0,4) to row5.ADDRESS.substring(0,5), since the other numbers all increased by 1 (i.e 3 to 4, and 10 to 11).</description>
      <pubDate>Thu, 15 Nov 2018 14:51:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251906#M35709</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-15T14:51:56Z</dc:date>
    </item>
    <item>
      <title>Re: StringIndexOutOfBoundsException: String index out of range: 40 how to fix</title>
      <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251907#M35710</link>
      <description>&lt;P&gt;What do you mean? Sorry, but is that a serious answer?&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 14:53:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251907#M35710</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-15T14:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: StringIndexOutOfBoundsException: String index out of range: 40 how to fix</title>
      <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251908#M35711</link>
      <description>&lt;P&gt;Yes, although on looking at your post again, I think I switched the expression that works with the one that doesn't. The one that works is:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%Refer%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("ABC") + 4),(row5.ADDRESS.indexOf("ABC") + 11))).replace("-", "").replaceAll("\\D*",""))&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;correct? And for the second expression, you copied this and updated the "index numbers", right?&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%TOSL%") ? row5.ADDRESS.substring(0,4): ((row5.ADDRESS.substring((row5.ADDRESS.indexOf("to") + 3),(row5.ADDRESS.indexOf("to") + 10))).replace("-", "").replaceAll("\\D*",""))&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;I think the issue is with row5.ADDRESS.substring(0,4); the row5.ADDRESS.contains("%TOSL%") can return a string of length 3 ("TOSL"), so it should be row5.ADDRESS.substring(0,3). Otherwise, when it returns "TOSL", you're trying to read position 4 in a zero-indexed string, which is out of bounds.&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Nov 2018 21:22:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251908#M35711</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-15T21:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: StringIndexOutOfBoundsException: String index out of range: 40 how to fix</title>
      <link>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251909#M35712</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&lt;A href="https://community.qlik.com/s/profile/0053p000007LM4pAAG"&gt;@DVSCHWAB&lt;/A&gt;&lt;/P&gt; 
&lt;P&gt;Thanks for taking time to response on my question, I fixed this by doing the code below:&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;row5.ADDRESS.contains("%REFER%") ? row5.ADDRESS.trim(): ((row5.ADDRESS.substring(row5.ADDRESS.indexOf("ABC") +4, Math.min(row5.ADDRESS.indexOf("ABC") + 11, row5.ADDRESS.length())).replace("-","").replaceAll("\\D","")))&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;The key is to use the "Math.min and length"&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt; 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 04:24:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Talend-Studio/StringIndexOutOfBoundsException-String-index-out-of-range-40-how/m-p/2251909#M35712</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-11-16T04:24:26Z</dc:date>
    </item>
  </channel>
</rss>

