[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

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 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend

Blog