How To Remove Text From A Text Variable

From Q
Jump to: navigation, search

Removing text from a Text variable

To remove text from within a Text variable:

  1. Create > Variables and Questions > Variable(s) > JavaScript Formula(s) > Text.
  2. In the Expression field, type an expression using the replace method. For example, if your variable was called Vcust1, and it contained commas that you wished to remove, you would write the expression: (Vcust1).replace(/,/g,""). Here, /,/g means that you wish to find all instances of commas. If modifying this expression for other purposes, change the first comma (between the forward slashes) to whatever text you wish to find, and type whatever you wish to replace it with between the two double quotes. See Manipulating Text with JavaScript for more ways of manipulating text.
  3. Press OK.

Removing text from a text variable when creating a numeric variable

When you change the Question Type from a Text question to Number, Q automatically converts the text to numbers. However, if a non-numeric character is encountered, Q will ignore it and all characters that follow. For example, 123,456,789 will change to 123. This problem is solved by replacing the text as follows:

  1. Change the Question Type to Number.
  2. Right-click on the new variable that is created and select Edit Variable.
  3. You will see an expression such as Q.AsNumeric(Vcust1);, where Vcust1 is the name of the original text variable. Modify this expression by replacing Vcust1 with another expression that replaces the text. For example, if replacing commas, as in the example above, your final expression would be Q.AsNumeric((Vcust1).replace(/,/g,""));.
  4. Press OK.
Personal tools