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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
EV89
Contributor III
Contributor III

Insert string inside another string

Hi Gurus,

 

how is it the best practice to insert some "-" characters inside another string to format the code?

 

for example, i have a code of xxxxxxxx digit and i want turn it in x-xxx-xxxx.

 

Thanks for  your help

 

 

Labels (2)
4 Replies
Anonymous
Not applicable

No idea if it is the best option but I would split the code and concatenate with "-", you can do it all in a tmap component.

 

EV89
Contributor III
Contributor III
Author

I add trhee rows in tmap1 and compute the single part of the code.

 

StringHandling.LEFT(dt.trainings_code_formatted,1) first part of the code COD1

StringHandling.LEFT(StringHandling.RIGHT(dt.trainings_code_formatted,7),3) middle part of the code COD2

StringHandling.RIGHT(dt.trainings_code_formatted,4) last part of the code COD3

 

In tmap2 i concatenate the different fields

 

dt1.COD1 + "-" + dt1.COD2 + "-" + dt1.COD3

EV89
Contributor III
Contributor III
Author

Thank you for your answer. What tMap components do you use in order to accomplish this task? can you post a little script?

 

Thanks

Anonymous
Not applicable

I don't really know if these options are better than the one you already did. They are practically the same. 

Option 1) 

StringHandling.LEFT(dt.trainings_code_formatted,1) + "-" + StringHandling.LEFT(StringHandling.RIGHT(dt.trainings_code_formatted,7),3) + "-" + StringHandling.RIGHT(dt.trainings_code_formatted,4) 

 

Option 2) 

In the tmap do variables where you calculate CODE1, CODE2 and CODE3 and in you output field the CODE1+ "-" +CODE2+ "-" +CODE3.