---
title: String functions
slug: analytics/docs/string-functions
docTags: 
createdAt: 2026-07-20T15:44:48.660Z
---

Outlines the string operations you can perform using NetScript.

## 'string'

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

:::hint{type="info"}
**Note**

Single quotes are not supported within string literals.
:::

**Function**

```auto
'string'
```

**Data type** – string

**Example**

```auto
'hello world'
```

**Result**

```auto
hello world
```

## 'string1 + string2'

Use this function to concatenate two strings.

**Function**

```auto
'string1 + string2'
```

**Data type** – string

**Example**

```auto
'hello + world'
```

**Result**

```auto
hello world
```

## 'string1' in 'string2'

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

**Function**

```auto
'string1' in 'string2'
```

**Data type** – boolean

**Example**

```auto
'fruit' in 'Bowl of fruit'
'fruit' in 'Bowl of vegetables'
```

**Result**

```auto
true
false
```

## 'string1' contains 'string2'

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

**Function**

```auto
'string1' contains 'string2'
```

**Data type** – boolean

**Example**

```auto
'fruit' contains 'it'
'fruit' contains 'Bowl of fruit'
```

**Result**

```auto
true
false
```

## substring(input)

Use this function to create a substring of any string. The input can be any value.

**Function**

```auto
substring(input)
```

**Data type** – string

**Example**

```auto
substring('abc', 0, 1)
```

**Result**

```auto
a
```

## to\_string(input)

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

**Function**

```auto
to_string(input)
```

**Data type** – string

**Example**

```auto
to_string(5)
```

**Result**

```auto
5
```

## lowercase('string')

Use this function to convert a string to lowercase.

**Function**

```auto
lowercase('string')
```

**Data types** – string

**Example**

```auto
lowercase('HELLO')
```

**Result**

```auto
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**

```auto
regexp_instr
```

**Data type** – string

**Example**

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

**Result**

```auto
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**

```auto
regexp_substr
```

**Data type** – string

**Example**

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

**Result**

```auto
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**

```auto
regexp_count
```

**Data type** – string

**Example**

```auto
regexp_count('abracadabra', 'abra')
```

**Result**

```auto
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**

```auto
regexp_replace
```

**Data type** – string

**Example**

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

**Result**

```auto
abc_number
```

## strlen

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

**Function**

```auto
strlen
```

**Data type** – string

**Example**

```auto
strlen('hello')
```

**Result**

```auto
5
```

## trim

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

**Function**

```auto
trim
```

**Data type** – string

**Example**

```auto
trim(' a ')
```

**Result**

```auto
'a'
```
