[resolved] Tmap and substring function

One Star

[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.

Accepted Solutions
One Star

Re: [resolved] Tmap and substring function

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

All Replies
One Star mpa
One Star

Re: [resolved] Tmap and substring function

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
One Star

Re: [resolved] Tmap and substring function

it was some problem with my installation. once I restarted it, all worked fine :-)
Thanks for your help
One Star mpa
One Star

Re: [resolved] Tmap and substring function

I'm glad it's working Smiley Very Happy

What’s New for Talend Spring ’19

Join us live for a sneak peek!

Sign up now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads