Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

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

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

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.



2 Replies
jonashertz
New Contributor III

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

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

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

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.