Apply

How to Return a Substring of Characters from a String (SUBSTR)

Using Advanced Expression Piping within your forms you can create mathematical formulas in order to calculate a value. Use SUBSTR to return a set number of characters from a variable. For example, return the first 4 characters from the answer to a question.

The SUBSTR function allows you to return a set number of characters from the variable based on the index positions defined in the second and third values in the expression.

For example, if the applicant provides a 10 digit phone number to question 1, and we want to extract the area code of the number (the first three digits) we can use the expression: {{ SUBSTR(q1, 0, 3) }}. If the applicant responds to the question with 613555555, then the expression will extract and return 613 as the response. 

The setup and formatting of the SUBSTR expression is imperative in preventing an error message from appearing on your form where the result of your expression would normally appear. The first line of the SUBSTR expression should be set up as follows: 

{{ SUBSTR(identifier, int, int) }}
  • The second value defines the starting position of the substring (inclusive) while the third value dictates the ending position (exclusive).
  • Returns the substring of characters based on the parameters stated in the expression
  • The index count for the SUBSTR function is 0 indexed
  • Each expression is always contained within a pair of double brackets {{  }}
  • There should be a space between the first instance of STR and the last bracket
  • Identifiers are case sensitive
  • Always close each SUBSTR operation with brackets ( )