- Posts: 162
- Thank you received: 14
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Regular Expression to parse integer from answer code
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
7 years 4 months ago #143861
by teracomp
Dave Phillips
Regular Expression to parse integer from answer code was created by teracomp
The way I've setup my Likert5 answers, each answer code is A1..A5.
All questions are mandatory, so there will be an answer for each.
My summary Equation Question then computes the totals for a particular set of questions, for example:
{sum(if(C1AQ1=='A1', 1, 0),if(C1AQ1=='A2', 2, 0),if(C1AQ1=='A3', 3, 0))}
This works, but if you look at it, 'A1' == 1 and 'A2' == 2. I have 10 questions per section when means I will have 50 equations to add 10 values.
If I could use something like preg_replace('[^\d]','', C1AQ1) the answer would produce 1..5 as desired.
The resulting equation would then be {sum(preg_replace('[^\d]','', C1AQ1),preg_replace('[^\d]','', C1AQ2), etc.)}
While I can write the 50 equation solution, is there a way to simply extract the integer value from the answer?
All questions are mandatory, so there will be an answer for each.
My summary Equation Question then computes the totals for a particular set of questions, for example:
{sum(if(C1AQ1=='A1', 1, 0),if(C1AQ1=='A2', 2, 0),if(C1AQ1=='A3', 3, 0))}
This works, but if you look at it, 'A1' == 1 and 'A2' == 2. I have 10 questions per section when means I will have 50 equations to add 10 values.
If I could use something like preg_replace('[^\d]','', C1AQ1) the answer would produce 1..5 as desired.
The resulting equation would then be {sum(preg_replace('[^\d]','', C1AQ1),preg_replace('[^\d]','', C1AQ2), etc.)}
While I can write the 50 equation solution, is there a way to simply extract the integer value from the answer?
Dave Phillips
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
7 years 4 months ago #143864
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Regular Expression to parse integer from answer code
I am not sure if I understand, but why don't you just write the code as 1, 2, 3 instead of A1, A2, A3 in the first place?
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
7 years 4 months ago #143865
by teracomp
Dave Phillips
Replied by teracomp on topic Regular Expression to parse integer from answer code
And so I'm embarrassed again. I thought codes had to start with a letter. *sigh*
Thanks
Thanks
Dave Phillips
The topic has been locked.
- holch
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
7 years 4 months ago #143867
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Regular Expression to parse integer from answer code
Hahahaha, don't worry. This happens. Sometimes we don't think of the most obvious solutions.
As far as I know the answer code does not need to start with a number. At least it works with just numbers very well, because this is what I use.
However, there is also another solution, for example if you want the answer codes to be consecutive, but the "points" to be different, e.g. 1=1, 2=1, 3=1, 4=5, 5=10, then you can use assessments and add these codes there and then access them via questioncode.value
As far as I know the answer code does not need to start with a number. At least it works with just numbers very well, because this is what I use.
However, there is also another solution, for example if you want the answer codes to be consecutive, but the "points" to be different, e.g. 1=1, 2=1, 3=1, 4=5, 5=10, then you can use assessments and add these codes there and then access them via questioncode.value
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: teracomp
The topic has been locked.
- teracomp
- Topic Author
- Offline
- Elite Member
Less
More
- Posts: 162
- Thank you received: 14
7 years 4 months ago #143868
by teracomp
Dave Phillips
Replied by teracomp on topic Regular Expression to parse integer from answer code
That is awesome! Thanks VERY much!!!
Dave Phillips
The topic has been locked.