Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap_2 String index out of range: -2

Hi,

 

I am using a tMap component with an expression to split a string with the following syntax:

 

row1.xxxx == null ? null : row1.xxxx.substring(0, (row1.xxxx.indexOf(" ")-1))

 

However, when I run the job I get error:  "tMap_2 String index out of range: -2".

 

Can someone please advise?

 

Thanks!

 

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi,

 

This expression solved the problem:

 

(row17.xxxx == null || StringHandling.LEN(row17.xxxx) == 0) ? null : row17.xxxx.substring(0, (row17.xxxxL.indexOf(" ")-1))

 

I realized my data had string values of null characters, thus the String.Handling.LEN was needed.

 

 

Thank you for your help!

 

 

View solution in original post

6 Replies
TRF
Champion II
Champion II

I prefer this method:

row1.xxxx == null ? null : row1.xxxx.replaceAll(" .*$", "")
manodwhb
Champion II
Champion II

@Larsi_88 ,You can the below way.

 

row7.newColumn == null ? null : (StringHandling.LEN(row7.newColumn)>3?(row7.newColumn.substring(0, (row7.newColumn .indexOf(" ")-1))):row7.newColumn)

TRF
Champion II
Champion II

@Larsi_88 does this help?
If so thanks to mark your case as solved
(Kudos also appreciated)
Anonymous
Not applicable
Author

Hi,

 

This expression solved the problem:

 

(row17.xxxx == null || StringHandling.LEN(row17.xxxx) == 0) ? null : row17.xxxx.substring(0, (row17.xxxxL.indexOf(" ")-1))

 

I realized my data had string values of null characters, thus the String.Handling.LEN was needed.

 

 

Thank you for your help!

 

 

TRF
Champion II
Champion II

@Larsi_88, I'm afraid you have chosen the most expensive and the least elegant solution (even if it works)!
Anonymous
Not applicable
Author

Hi,

 

My job failed again. Does the exrepssion:

row1.xxxx == null ? null : row1.xxxx.replaceAll(" .*$", "")

 replace my solution completely?