Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

In QlikView or Sense what is equivalent to a String builder in Java?

Hi all,

In Java it is easy to drop this code inside a for loop and then get a nicely concatenated string.

a = new StringBuilder()
  
.append(a)
  
.append(b)
  
.toString();


However I haven't been able to do the same in Qlik Sene. I am trying to achieve something like this:


Let vMyVar = 'some text ';

For i = 1 to 3

vMyVar += i + Peek('City', $(i), 'weatherdata');

Next

Trace $(vMyvar );


Where $(vMyvar) must be in the end => some text 1 France 2 Madrid 3 Lund


I hope this is clear


Many thanks

1 Solution

Accepted Solutions
Not applicable
Author

Hi Jonas,

This works give one small correction in the code:

let vMyVar = '';

For i = 1 to 3

vMyVar = '$(vMyVar)' & ' ' & Peek('City', $(i), 'weatherdata');

Next

Trace $(vMyVar);


Note the single quotation around $(vMyVar).


I will still test it later with real data from the net and see what happens. I wished the Qlik syntax was more flexible like Java, JS or even action script, not sure into which category to put it

Thank you very much for your answer it was helpful and confirm something similar I found yesterday night.



View solution in original post

2 Replies
kjhertz
Partner - Creator
Partner - Creator

I can think of two ways to achieve this right of the bat.

1. Use a variable in the loop:

let vMyVar = '';

For i = 1 to 3

vMyVar = $(vMyVar) & ' ' & Peek('City', $(i), 'weatherdata');

Next

Trace $(vMyVar);


2. Use Concat() to get all text rows of one table into the same row. Perhaps you need to merge your city and number field first and then concat:


The Concat Function

Not applicable
Author

Hi Jonas,

This works give one small correction in the code:

let vMyVar = '';

For i = 1 to 3

vMyVar = '$(vMyVar)' & ' ' & Peek('City', $(i), 'weatherdata');

Next

Trace $(vMyVar);


Note the single quotation around $(vMyVar).


I will still test it later with real data from the net and see what happens. I wished the Qlik syntax was more flexible like Java, JS or even action script, not sure into which category to put it

Thank you very much for your answer it was helpful and confirm something similar I found yesterday night.