Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Extracting a substring from a string

Hello,

Being a recent convert from DataStage to Talend I am looking for a string function which does the equivalent of the Field function in DataStage.  Here's how the Field function works:

 

MainString = "AAA;BBB;CCC;DDD"

X = Field(MainString, ';', 3) = "CCC"

 

The function recognises a "string to search" - MainString, a separator - ";", and the index of the substring - 3

I would be grateful if anyone can suggest how this functionality can be replicated in a tmap column derivation expression?

 

Many thanks,

Bob

 

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Thank you both, I thought it might be in there somewhere!

View solution in original post

3 Replies
akumar2301
Specialist II
Specialist II

 

try {

x = MainString.split(";")[2];

}catch ( Exception e) {

x = "Not found";

}

Anonymous
Not applicable
Author

Hi @bob_oxtoby 

 

    First of all, welcome to the world of Talend 🙂

 

    Below is a slightly different version of Abhi's solution using tMap where I am using context variables to pass the separator and index to pick.

 

0683p000009M3Bv.png

 

0683p000009M3Xf.png

 

0683p000009M3Xk.png

 

row1.data.split(context.separator)[context.index] 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

 

Anonymous
Not applicable
Author

Thank you both, I thought it might be in there somewhere!