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

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] Tmap and substring function

Hi all,
I have tmap. The input is coming in one string as follows:
<html><head><title>bbasasas</title><body>dasdad</body></html>
What I am interested in is to get everything between <body> </body> tags
so I am trying to do the following expression:
input.htmlstring.substring(input.htmlstring.indexOf("<body>"), input.htmlstring.indexOf("</body>"))

Now, for some reason I get the follow error:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1

Any idea where I am going wrong? Thanks.
Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

it was some problem with my installation. once I restarted it, all worked fine 🙂
Thanks for your help

View solution in original post

3 Replies
Anonymous
Not applicable
Author

Hi,
I don't know what you did wrong, but I tried it in my talend version.
Maybe I did it difficult because i couldn't find a substring function in my talend version, but I got it working.
So I made 2 variables in my tMap component: htmlRight and htmlLeft.
htmlright contains:
StringHandling.RIGHT(Input.htmlstring,(StringHandling.LEN(Input.htmlstring) - StringHandling.INDEX(Input.htmlstring ,"<body>")-6))
htmlleft contains:
StringHandling.LEFT(Var.htmlright,(StringHandling.LEN("Var.htmlright") - StringHandling.INDEX(Var.htmlright ,"</body>")-1))
The variable htmlleft then contains what is between the body tags.
Regards,
Mario De Pauw
Anonymous
Not applicable
Author

it was some problem with my installation. once I restarted it, all worked fine 🙂
Thanks for your help
Anonymous
Not applicable
Author

I'm glad it's working 0683p000009MACJ.png