Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Input the answer from a free short text question in another short text question

  • MarieLB
  • MarieLB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #189366 by MarieLB
Hi everyone,

I would like to get the answer of my free short text question and put it in another text question to be able to separate it in subsequences.
The answer to the first question is a random number serie (for exemple #,6,5,9,4,2,10,8,1,3,7,) and I would like to cut this sequence in two in the next two text questions (#,6,5,9,4,2 and #10,8,1,3,7,).

I'm using {qID.shown} but I'm only seeing the first number of the sequence.

You can see what I tried to do in the attachments.


I'm new to LimeSurvey and I'm a beginner with Java, so I'm sorry if it is something obvious but I'm really lost.

Thanks a lot if you take the time to think about it and answer me !!

Attachment not found

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #189368 by Joffm
Hi, with this structure of your string you can split by these two equations

{subSeq1=substr(RandomSeq,0,strpos(RandomSeq,",",11)+1)}

{subSeq2=join("#",substr(RandomSeq,strpos(RandomSeq,",",11)))}




I would like to cut this sequence in two in the next two text questions (#,6,5,9,4,2 and #10,8,1,3,7,).

It only works to split into two and I assume that the two strings have the same structure, ALL elements separated by comma and a tailing comma, too.

File Attachment:

File Name: limesurvey...0-01.lss
File Size:34 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 5 months ago by Joffm.
The following user(s) said Thank You: MarieLB
The topic has been locked.
  • MarieLB
  • MarieLB's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #189376 by MarieLB
Thank you so much !
I have one more question. Is there an easy answer to separate in more than 2 subsequences or is it too complex ? I get why you can't use substr to create 3 subsequence as there is no end option, only a length string option. I looked at the implemented functions to see if I could find something similar but with no luck.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #189394 by Joffm
Well, the trick was, that the comma between the 5th and 6th element is always at position 11 or 12 (depending whether "10" is in the first or second part)
So it's easy to split by the offset parameter of "strpos".
This is a lot more difficult if you try to split into three parts. Where is the 10th element?
4-3-3, or 3-4-3, or 3-3-4?

Of course you can try to:
  • leftpad all elements
  • remove the comma
You will have a string like "01050710090204080306"
which you can split easily. (here 3-3-4)
string1: substr(Q1,0,6)
string2: substr(Q1,6,6)
string3: substr(Q1,12)

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 4 years 5 months ago by Joffm.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose