sgapiSubStr(%%string,%%start = 0,%%length = 255)

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!

Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

This is equivalent to the substr function in PHP. This function returns the portion of string specified by the offset and length parameters.

If start is non-negative, the returned string will start at the start position in string, counting from zero. For instance, in the string 'abcdef' the character at position 0 is 'a' the character at position 2 is 'c' and so forth.

If start is negative, the returned string will start at the start character from the end of string.

If string is less than or equal to start characters long, FALSE will be returned.

If length is given and is positive, the string returned will contain at most length characters beginning from start (depending on the length of string).

If length is given and is negative, then that many characters will be omitted from the end of string (after the start position has been calculated when a start is negative). If start denotes the position of this truncation or beyond, false will be returned.

If length is given and is 0, FALSE or NULL an empty string will be returned.

If length is omitted, the substring starting from start until the end of the string will be returned.

Examples

The below exampe will return "a"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string,0,1)

The below example will return "f"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -1);

The below example will return "ef"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -2);

The below example will return "d"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = -3, %%length = 1);

The below example will return "cde"

%%string = 'abcdef';

%%output .= sgapiSubStr(%%string, %%start = 2, %%length = -1);

To see an example or learn more other PHP functions and PHP programming, visit PHP Documentation.