In this article
In the following examples, an Open Text question as in q2 of the Car study - - is used.
Figure 1 - Example of an Open Text question
Search for Open text answers
If you wish to search for specific names or character combinations in the question q2, you could use the following expression:
if (q2.Contains("name1")) { }Using this example you would search for “name1” in variable q2. Inside the final brackets you would usually specify an action that would be performed if “name1” is found in a given answer. You could for example replace the found text with a different one, or set a value for another variable.
You can also search for specific texts at the beginning or end of a given answer:
if (q2.StartsWith("a") || q2.EndsWith("z")) { }This expression would search for “a” at the beginning of the given answer and “z” at the end of the given answer.
Replace Open Text answers
If you would like to replace the given answer with a different text, you could use the following expression:
if (q2.Contains("name1"))
{
q2 = q2.Replace ("name1", "new name");
}In this example, “name1” would be replaced by “new name”.
Open Text Numeric Variables
An Open Text Numeric question could for example ask for the respondent's salary - -:
Figure 2 - Example of an Open Text Numeric question
If you would like to check for an income higher than a certain amount, for example $20000, you could write:
if (q9 > 20000) { }Inside the brackets you must specify the action that should be executed if a respondent gives a higher income. If you would like to calculate for example a new income and overwrite the existing value:
if (q9 > 20000)
{
q9 = q9 * ( q9 / 33);
}