[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

View solution in original post


All Replies
Highlighted
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

View solution in original post

One Star mpa
One Star

Re: [resolved] Tmap and substring function

I'm glad it's working Smiley Very Happy

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog