- Posts: 2
- Thank you received: 0
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
- Topic Author
- Offline
- New Member
Less
More
4 years 5 months ago #189366
by MarieLB
Input the answer from a free short text question in another short text question was created 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 !!
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
Attachments:
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12779
- Thank you received: 3940
4 years 5 months ago - 4 years 5 months ago #189368
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Input the answer from a free short text question in another short text question
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)))}
Joffm
{subSeq1=substr(RandomSeq,0,strpos(RandomSeq,",",11)+1)}
{subSeq2=join("#",substr(RandomSeq,strpos(RandomSeq,",",11)))}
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.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,).
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
Last edit: 4 years 5 months ago by Joffm.
The following user(s) said Thank You: MarieLB
The topic has been locked.
- MarieLB
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
4 years 5 months ago #189376
by MarieLB
Replied by MarieLB on topic Input the answer from a free short text question in another short text question
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.
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12779
- Thank you received: 3940
4 years 5 months ago - 4 years 5 months ago #189394
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Input the answer from a free short text question in another short text question
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:
which you can split easily. (here 3-3-4)
string1: substr(Q1,0,6)
string2: substr(Q1,6,6)
string3: substr(Q1,12)
Joffm
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
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.