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
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 4 months ago #143861 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?

Dave Phillips
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 4 months ago #143864 by holch
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
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 4 months ago #143865 by teracomp
And so I'm embarrassed again. I thought codes had to start with a letter. *sigh*

Thanks

Dave Phillips
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 4 months ago #143867 by holch
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

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
  • teracomp's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
More
7 years 4 months ago #143868 by teracomp
That is awesome! Thanks VERY much!!!

Dave Phillips
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose