多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
5.5 KiB

---
title: 'String functions'
description: 'This article explains various string functions that can be used in formula fields.'
tags: ['Fields', 'Field types', 'Formula']
keywords: ['Fields', 'Field types', 'Formula', 'Create formula field', 'String functions']
---
This cheat sheet provides a quick reference guide for various string based functions commonly used in data analysis and programming. Each function is accompanied by its syntax, a sample usage, and a brief description.
## CONCAT
The CONCAT function concatenates one or more strings into a single string.
#### Syntax
```plaintext
CONCAT(text, [text,...])
```
#### Sample
```plaintext
CONCAT('John', ' ', 'Doe') => 'John Doe'
```
## LEFT
The LEFT function retrieves the first 'n' characters specified from the beginning of the input string.
#### Syntax
```plaintext
LEFT(text, count)
```
#### Sample
```plaintext
LEFT('123-456-7890', 3) => '123'
```
## LEN
The LEN function calculates and returns the total number of characters present in the provided string.
#### Syntax
```plaintext
LEN(text)
```
#### Sample
```plaintext
LEN('Product Description') => 19
```
## LOWER
The LOWER function transforms all characters in the input string to lowercase
#### Syntax
```plaintext
LOWER(text)
```
#### Sample
```plaintext
LOWER('User INPUT') => 'user input'
```
## MID
The MID function retrieves a substring from the input string starting at the specified position and extending for the specified count of characters.
#### Syntax
```plaintext
MID(text, position, [count])
```
#### Sample
```plaintext
MID('This is a sentence', 5, 3) => 'is '
```
## REGEX_EXTRACT
The REGEX_EXTRACT function searches the input string for the first occurrence of the specified regular expression pattern and returns the matched substring.
#### Syntax
```plaintext
REGEX_EXTRACT(text, pattern)
```
#### Sample
```plaintext
REGEX_EXTRACT('Error: Something went wrong', 'Error: (.*)') => 'Something went wrong'
```
## REGEX_MATCH
The REGEX_MATCH function evaluates whether the input string matches the specified regular expression pattern, returning 1 if there is a match and 0 if there is no match.
#### Syntax
```plaintext
REGEX_MATCH(text, pattern)
```
#### Sample
```plaintext
REGEX_MATCH('123-45-6789', '\d{3}-\d{2}-\d{4}') => 1
```
## REGEX_REPLACE
The REGEX_REPLACE function identifies all occurrences of the specified regular expression pattern in the input string and substitutes them with the provided replacement string.
#### Syntax
```plaintext
REGEX_REPLACE(text, pattern, replacer)
```
#### Sample
```plaintext
REGEX_REPLACE('Replace all bugs', 'bug', 'feature') => 'Replace all features'
```
## REPEAT
The REPEAT function duplicates the provided string the specified number of times, facilitating the creation of repeated patterns or sequences.
#### Syntax
```plaintext
REPEAT(text, count)
```
#### Sample
```plaintext
REPEAT('😃', 3) => '😃😃😃'
```
## REPLACE
The REPLACE function identifies all instances of a particular substring within the given string and substitutes them with another specified substring.
#### Syntax
```plaintext
REPLACE(text, srchStr, rplcStr)
```
#### Sample
```plaintext
REPLACE('Replace old text', 'old', 'new') => 'Replace new text'
```
## RIGHT
The RIGHT function retrieves the last 'n' characters from the end of the input string, allowing you to extract a substring starting from the right.
#### Syntax
```plaintext
RIGHT(text, n)
```
#### Sample
```plaintext
RIGHT('file_name.txt', 3) => 'txt'
```
## SEARCH
The SEARCH function identifies the position of the specified substring within the input string, returning the index if found, and 0 otherwise.
#### Syntax
```plaintext
SEARCH(text, srchStr)
```
#### Sample
```plaintext
SEARCH('user@example.com', '@') => 5
```
## SUBSTR
The SUBSTR function extracts a substring from the input string, starting at the specified position and optionally extending for the specified count of characters.
#### Syntax
```plaintext
SUBSTR(text, position, [count])
```
#### Sample
```plaintext
SUBSTR('Extract this text', 9, 4) => 'this'
```
## TRIM
The TRIM function eliminates any leading or trailing whitespaces from the input string.
#### Syntax
```plaintext
TRIM(text)
```
#### Sample
```plaintext
TRIM(' Trim this ') => 'Trim this'
```
## UPPER
The UPPER function transforms all characters in the input string to uppercase.
#### Syntax
```plaintext
UPPER(text)
```
#### Sample
```plaintext
UPPER('title') => 'TITLE'
```
## URL
The URL function checks if the input string is a valid URL and converts it into a hyperlink
#### Syntax
```plaintext
URL(text)
```
#### Sample
```plaintext
URL('https://www.example.com') => a clickable link for https://www.example.com
```
## URLENCODE
The URLENCODE function percent-encodes special characters in a string so it can
be substituted as a query parameter into a URL.
It is similar to JavaScript `encodeURIComponent()` function, except it encodes
only characters that have a special meaning according to RFC 3986 section 2.2
and also percent signs and spaces; other characters such as letters from
non-Latin alphabets will not be encoded. Like `encodeURIComponent()`, it should
be used only for encoding URL components, not whole URLs.
#### Syntax
```plaintext
URLENCODE(text)
```
#### Sample
```plaintext
'https://example.com/q?param=' & URLENCODE('Hello, world')
=> 'https://example.com/q?param=Hello%2C%20world'
```
## Related Articles
- [Numeric and Logical Operators](015.operators.md)
- [Numeric Functions](020.numeric-functions.md)
- [Date Functions](040.date-functions.md)
- [Conditional Expressions](050.conditional-expressions.md)