String functions

  • Updated

Outlines the string operations you can perform using NetScript.

'string'

Use this function to return a string literal. Enclose your string within single quotes.

Single quotes are not supported within string literals.

Function

'string'

Data type – string

Example

'hello world'

Result

hello world

'string1 + string2'

Use this function to concatenate two strings.

Function

'string1 + string2'

Data type – string

Example

'hello + world'

Result

hello world

'string1' in 'string2'

Use this function to check if string1 is a substring of string2. It returns a boolean value.

Function

'string1' in 'string2'

Data type – boolean

Example

'fruit' in 'Bowl of fruit'
'fruit' in 'Bowl of vegetables'

Result

true
false

'string1' contains 'string2'

Use this function to check if string2 is a substring of string1. It returns a boolean value.

Function

'string1' contains 'string2'

Data type – boolean

Example

'fruit' contains 'it'
'fruit' contains 'Bowl of fruit'

Result

true
false

to_string(input)

Use this function to cast any input to a string. The input can be any value.

Function

to_string(input)

Data type – string

Example

to_string(5)

Result

5

lowercase('string')

Use this function to convert a string to lowercase.

Function

lowercase('string')

Data types – string

Example

lowercase('HELLO')

Result

hello

regexp_instr

Use this function to find the position of the first occurrence of a substring that matches a given regular expression (regex) within a string. The position is 1-based, meaning it starts counting from 1. The first argument is the string you want to search, and the second is the regex pattern. If either argument is null, the function returns null. If the regex pattern is invalid, it throws an error. If there is no match, it returns 0.

Function

regexp_instr

Data type – string

Example

regexp_instr(‘abc1’, ‘[0-9]’)

Result

4

regexp_substr

Use this function to find and return the first substring that matches a given regex pattern within a string. The first argument is the string to search, and the second is the regex pattern. The function returns null if either argument is null or no match is found. If the regex pattern is invalid, it throws an error.

Function

regexp_substr

Data type – string

Example

regexp_substr(‘abc1’, ‘[0-9]’)

Result

1

regexp_count

Use this function to count how often a specified pattern appears in a string. The first argument is the string to search, and the second is the count pattern.

Function

regexp_count

Data type – string

Example

regexp_count('abracadabra', 'abra')

Result

2

regexp_replace

Use this function to replace all occurrences of a specified pattern within a string with a replacement string. The first argument is the original string, the second is the pattern to be replaced, and the third is the replacement string. If no matches are found, the function returns the original string.

Function

regexp_replace

Data type – string

Example

regexp_replace('abc123', '[0-9]*', '_number')

Result

abc_number

strlen

Use this function to determine the number of characters in a string. Provide the string as the argument.

Function

strlen

Data type – string

Example

strlen('hello')

Result

5

trim

Use this function to remove any leading and trailing spaces from a string. Provide the string as the argument.

Function

trim

Data type – string

Example

trim(' a ')

Result

'a'