Skip to content

String#

String.base64Decode()#

Description: 将 base64 编码的字符串转换为纯文本

Syntax: String.base64Encode()

Returns: String

Source: Custom n8n functionality

Examples:

1
"aGVsbG8=".base64Decode() //=> "hello"

String.base64Encode()#

Description: 将纯文本转换为 base64 编码的字符串

Syntax: String.base64Encode()

Returns: String

Source: Custom n8n functionality

Examples:

1
"hello".base64Encode() //=> "aGVsbG8="

String.concat()#

Description: 将一个或多个字符串连接到基础字符串的末尾。也可以使用 + 运算符(参见示例)。

Syntax: String.concat(string1, string2?, ..., stringN?)

Returns: String

Source: JavaScript function

Parameters:

  • string1 (String) - 要追加的第一个字符串
  • string2 (String) - 可选 - 要追加的第二个字符串
  • stringN (String) - 可选 - 要追加的第 N 个字符串

Examples:

1
2
'sea'.concat('food') //=> 'seafood'
'sea' + 'food' //=> 'seafood'
1
'work'.concat('a', 'holic') //=> 'workaholic'

String.extractDomain()#

Description: 如果字符串是电子邮件地址或 URL,则返回其域名(如果未找到则返回 undefined)。

如果字符串还包含其他内容,请先尝试使用 extractEmail()extractUrl()

Syntax: String.extractDomain()

Returns: String

Source: Custom n8n functionality

Examples:

1
"[email protected]".extractDomain() //=> 'example.com'
1
"http://n8n.io/workflows".extractDomain() //=> 'n8n.io'
1
"It's [email protected]".extractEmail().extractDomain() //=> 'example.com'

String.extractEmail()#

Description: 提取字符串中找到的第一个电子邮件地址。如果未找到则返回 undefined

Syntax: String.extractEmail()

Returns: String

Source: Custom n8n functionality

Examples:

1
"My email is [email protected]".extractEmail() //=> '[email protected]'

String.extractUrl()#

Description: 提取字符串中找到的第一个 URL。如果未找到则返回 undefined。仅识别完整的 URL,例如以 http 开头的 URL。

Syntax: String.extractUrl()

Returns: String

Source: Custom n8n functionality

Examples:

1
"Check out http://n8n.io".extractUrl() //=> 'http://n8n.io'

String.extractUrlPath()#

Description: 返回 URL 中域名之后的部分,如果未找到 URL 则返回 undefined

如果字符串还包含其他内容,请先尝试使用 extractUrl()

Syntax: String.extractUrlPath()

Returns: String

Source: Custom n8n functionality

Examples:

1
"http://n8n.io/workflows".extractUrlPath() //=> '/workflows'
1
"Check out http://n8n.io/workflows".extractUrl().extractUrlPath() //=> '/workflows'

String.hash()#

Description: 使用指定的算法返回字符串的哈希值。未指定时默认使用 md5。

Syntax: String.hash(algo?)

Returns: String

Source: Custom n8n functionality

Parameters:

  • algo (String) - 可选 - 要使用的哈希算法。可选值:md5base64sha1sha224sha256sha384sha512sha3ripemd160

Examples:

1
"hello".hash() //=> '5d41402abc4b2a76b9719d911017c592'

String.includes()#

Description: 如果字符串包含 searchString,则返回 true。区分大小写。

Syntax: String.includes(searchString, start?)

Returns: Boolean

Source: JavaScript function

Parameters:

  • searchString (String) - 要搜索的文本
  • start (Number) - 可选 - 开始搜索的位置(索引)

Examples:

1
2
'team'.includes('tea') //=> true
'team'.includes('i') //=> false 
1
2
3
// Returns false if the case doesn't match, so consider using .toLowerCase() first
'team'.includes('Tea') //=> false
'Team'.toLowerCase().includes('tea') //=> true

String.indexOf()#

Description: 返回 searchString 在基础字符串中首次出现的索引(位置),如果未找到则返回 -1。区分大小写。

Syntax: String.indexOf(searchString, start?)

Returns: Number

Source: JavaScript function

Parameters:

  • searchString (String) - 要搜索的文本
  • start (Number) - 可选 - 开始搜索的位置(索引)

Examples:

1
2
'steam'.indexOf('tea') //=> 1
'steam'.indexOf('i') //=> -1 
1
2
3
// Returns -1 if the case doesn't match, so consider using .toLowerCase() first
'STEAM'.indexOf('tea') //=> -1
'STEAM'.toLowerCase().indexOf('tea') //=> 1

String.isDomain()#

Description: 如果字符串是域名,则返回 true

Syntax: String.isDomain()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"n8n.io".isDomain() //=> true
1
"http://n8n.io".isDomain() //=> false
1
"hello".isDomain() //=> false

String.isEmail()#

Description: 如果字符串是电子邮件地址,则返回 true

Syntax: String.isEmail()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"[email protected]".isEmail() //=> true
1
"It's [email protected]".isEmail() //=> false
1
"hello".isEmail() //=> false

String.isEmpty()#

Description: 如果字符串没有字符或为 null,则返回 true

Syntax: String.isEmpty()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"".isEmpty() // => true
1
"hello".isEmpty() // => false

String.isNotEmpty()#

Description: 如果字符串至少有一个字符,则返回 true

Syntax: String.isNotEmpty()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"hello".isNotEmpty() // => true
1
"".isNotEmpty() // => false

String.isNumeric()#

Description: 如果字符串表示一个数字,则返回 true

Syntax: String.isNumeric()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"1.2234".isNumeric() // true
1
"hello".isNumeric() // false
1
"123E23".isNumeric() // true

String.isUrl()#

Description: 如果字符串是有效的 URL,则返回 true

Syntax: String.isUrl()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"https://n8n.io".isUrl() //=> true
1
"n8n.io".isUrl() //=> false
1
"hello".isUrl() //=> false

String.length#

Description: 字符串中的字符数量

Syntax: String.length

Returns: Number

Source: JavaScript function

Examples:

1
"hello".length //=> 5

String.match()#

Description: 使用正则表达式匹配字符串。返回包含第一个匹配项的数组,如果正则表达式中设置了 g 标志则返回所有匹配项。如果没有找到匹配项则返回 null

如需检查文本是否存在,请考虑使用 includes()

Syntax: String.match(regexp)

Returns: Array

Source: JavaScript function

Parameters:

  • regexp (RegExp) - 包含要查找模式的正则表达式。如果设置了 g 标志,则会查找多个匹配项(参见示例)。

Examples:

1
2
// Match all words starting with 'r'
"rock and roll".match(/r[^ ]*/g) //=> ['rock', 'roll']
1
2
// Match first word starting with 'r' (no 'g' flag)
"rock and roll".match(/r[^ ]*/) //=> ['rock']
1
2
// For case-insensitive, add 'i' flag
"ROCK and roll".match(/r[^ ]*/ig) //=> ['ROCK', 'roll']

String.parseJson()#

Description: 返回字符串所表示的 JavaScript Object 或值,如果字符串不是有效的 JSON 则返回 undefined。不支持单引号 JSON。

Syntax: String.parseJson()

Returns: any

Source: Custom n8n functionality

Examples:

1
'{"name":"Nathan"}'.parseJson() //=> {"name":"Nathan"}
1
"{'name':'Nathan'}".parseJson() //=> undefined
1
'hello'.parseJson() //=> undefined

String.quote()#

Description: 用引号包裹字符串,并转义字符串中已有的引号。在构建 JSON、SQL 等时非常有用。

Syntax: String.quote(mark?)

Returns: String

Source: Custom n8n functionality

Parameters:

  • mark (String) - 可选 - 要使用的引号类型

Examples:

1
'Nathan says "hi"'.quote() //=> '"Nathan says \"hi\""'

String.removeMarkdown()#

Description: 移除字符串中的所有 Markdown 格式。同时也会移除 HTML 标签。

Syntax: String.removeMarkdown()

Returns: String

Source: Custom n8n functionality

Examples:

1
"*bold*, [link]()".removeMarkdown() //=> "bold, link"

String.removeTags()#

Description: 移除字符串中的标签,如 HTML 或 XML 标签

Syntax: String.removeTags()

Returns: String

Source: Custom n8n functionality

Examples:

1
"<b>bold</b>, <a>link</a>".removeTags() //=> "bold, link"

String.replace()#

Description: 返回将第一个匹配的 pattern 替换为 replacement 后的字符串。

如需替换所有匹配项,请使用 replaceAll()

Syntax: String.replace(pattern, replacement)

Returns: String

Source: JavaScript function

Parameters:

  • pattern (String|RegExp) - 字符串中要替换的模式。可以是要匹配的字符串或正则表达式
  • replacement (String) - 用于替换的新文本

Examples:

1
'Red or blue or green'.replace('or', 'and') //=> 'Red and blue or green'
1
2
3
// A global, case-insensitive replacement:
let text = "Mr Blue has a blue house and a blue car";
let result = text.replace(/blue/gi, "red");
1
2
3
4
5
// A function to return the replacement text:
let text = "Mr Blue has a blue house and a blue car";
let result = text.replace(/blue|house|car/i, function (x) {
  return x.toUpperCase();
});

String.replaceAll()#

Description: 返回将所有匹配的 pattern 替换为 replacement 后的字符串

Syntax: String.replaceAll(pattern, replacement)

Returns: String

Source: JavaScript function

Parameters:

  • pattern (String|RegExp) - 字符串中要替换的模式。可以是要匹配的字符串或正则表达式
  • replacement (String|function) - 用于替换的新文本。可以是字符串或返回字符串的函数(参见示例)。

Examples:

1
'Red or blue or green'.replace('or', 'and') //=> 'Red and blue and green'
1
2
3
4
5
6
7
8
// Uppercase any occurrences of 'blue' or 'car'
// (You must include the 'g' flag when using a regex)

// text = 'Mr Blue has a blue car'
text.replaceAll(/blue|car/gi, x => x.toUpperCase()) //=> 'Mr BLUE has a BLUE CAR'

// Or with traditional function notation:
text.replaceAll(/blue|car/gi, function(x){return x.toUpperCase()}) //=> 'Mr BLUE has a BLUE CAR'

String.replaceSpecialChars()#

Description: 将字符串中的特殊字符替换为最接近的 ASCII 字符

Syntax: String.replaceSpecialChars()

Returns: String

Source: Custom n8n functionality

Examples:

1
"déjà".replaceSpecialChars() //=> "deja"

String.search()#

Description: 返回字符串中第一个匹配模式的索引(位置),如果未找到则返回 -1。模式使用正则表达式指定。如需使用文本搜索,请参见 indexOf()

Syntax: String.search(regexp)

Returns: Number

Source: JavaScript function

Parameters:

Examples:

1
2
// Pos of first word starting with 'n'
"Neat n8n node".search(/n[^ ]*/) //=> 5
1
2
3
// Case-insensitive match with 'i'
// Pos of first word starting with 'n' or 'N'
"Neat n8n node".search(/n[^ ]*/i) //=> 0

String.slice()#

Description: 在指定位置提取字符串的片段。如需更高级的提取,请参见 match()

Syntax: String.slice(start, end?)

Returns: String

Source: JavaScript function

Parameters:

  • start (Number) - 开始位置。位置从 0 开始。负数表示从字符串末尾倒数。
  • end (String) - 可选 - 截取到的位置。该位置的字符不包含在内。负数表示从字符串末尾选取。省略时将提取到字符串末尾。

Examples:

1
'Hello from n8n'.slice(0, 5) //=> 'Hello'
1
'Hello from n8n'.slice(6) //=> 'from n8n'
1
'Hello from n8n'.slice(-3) //=> 'n8n'

String.split()#

Description: 将字符串拆分为子字符串数组。每次拆分在 separator 处进行,且分隔符不包含在输出中。

与对数组使用 join() 相反。

Syntax: String.split(separator?, limit?)

Returns: Array

Source: JavaScript function

Parameters:

  • separator (String) - 可选 - 用于拆分的字符串(或正则表达式)。省略时返回包含原始字符串的数组。
  • limit (Number) - 可选 - 返回的最大数组元素数。省略时返回所有元素。

Examples:

1
"wind,fire,water".split(",") //=> ['wind', 'fire', 'water']
1
"me and you and her".split("and") //=> ['me ', ' you ', ' her']
1
2
// Split one or more of space, comma and '?' using a regular expression
"me? you, and her".split(/[ ,?]+/) //=> ['me', 'you', 'and', 'her']

String.startsWith()#

Description: 如果字符串以 searchString 开头,则返回 true。区分大小写。

Syntax: String.startsWith(searchString, start?)

Returns: Boolean

Source: JavaScript function

Parameters:

  • searchString (String) - 用于检查基础字符串开头的文本
  • start (Number) - 可选 - 开始搜索的位置(索引)

Examples:

1
2
'team'.startsWith('tea') //=> true
'team'.startsWith('Tea') //=> false
1
2
// Returns false if the case doesn't match, so consider using .toLowerCase() first
'Team'.toLowerCase().startsWith('tea') //=> true

String.substring()#

Description: 在指定位置提取字符串的片段。如需更高级的提取,请参见 match()

Syntax: String.substring(start, end?)

Returns: String

Source: JavaScript function

Parameters:

  • start (Number) - 开始位置。位置从 0 开始。
  • end (String) - 可选 - 截取到的位置。该位置的字符不包含在内。省略时将提取到字符串末尾。

Examples:

1
'Hello from n8n'.substring(0, 5) //=> 'Hello'
1
'Hello from n8n'.substring(6) //=> 'from n8n'

String.toBoolean()#

Description: 将字符串转换为布尔值。0falseno 转换为 false,其他所有值转换为 true。不区分大小写。

Syntax: String.toBoolean()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
"true".toBoolean() //=> true
1
"false".toBoolean() //=> false
1
"0".toBoolean() //=> false
1
"hello".toBoolean() //=> true

String.toDateTime()#

Description: 将字符串转换为 DateTime。可用于进一步的转换操作。字符串支持的格式包括 ISO 8601、HTTP、RFC2822、SQL 和毫秒级 Unix 时间戳。

如需解析其他格式,请使用 DateTime.fromFormat()

Syntax: String.toDateTime()

Returns: DateTime

Source: Custom n8n functionality

Examples:

1
"2024-03-29T18:06:31.798+01:00".toDateTime()
1
"Fri, 29 Mar 2024 18:08:01 +0100".toDateTime()
1
"20240329".toDateTime()
1
"1711732132990".toDateTime()

String.toJsonString()#

Description: 将字符串准备好以便插入 JSON 对象。转义引号和特殊字符(如换行符),并用引号包裹字符串。

与 JavaScript 的 JSON.stringify() 相同。

Syntax: String.toJsonString()

Returns: String

Source: Custom n8n functionality

Examples:

1
2
// str = 'The "best" colours: red\nbrown'
str.toJsonString() //=> '"The \\"best\\" colours: red\\nbrown"'

String.toLowerCase()#

Description: 将字符串中的所有字母转换为小写

Syntax: String.toLowerCase()

Returns: String

Source: JavaScript function

Examples:

1
"I'm SHOUTing".toLowerCase() //=> "i'm shouting"

String.toNumber()#

Description: 将表示数字的字符串转换为数字。如果字符串不是以有效数字开头,则抛出错误。

Syntax: String.toNumber()

Returns: Number

Source: Custom n8n functionality

Examples:

1
"123".toNumber() //=> 123
1
"1.23E10".toNumber() //=> 12300000000

String.toSentenceCase()#

Description: 将字符串的大小写更改为句子格式。每个句子的首字母大写,其余字母小写。

Syntax: String.toSentenceCase()

Returns: String

Source: Custom n8n functionality

Examples:

1
"quick! brown FOX".toSentenceCase() //=> "Quick! Brown fox"

String.toSnakeCase()#

Description: 将字符串的格式更改为蛇形命名法。空格和破折号替换为 _,符号被移除,所有字母转为小写。

Syntax: String.toSnakeCase()

Returns: String

Source: Custom n8n functionality

Examples:

1
"quick brown $FOX".toSnakeCase() //=> "quick_brown_fox"

String.toTitleCase()#

Description: 将字符串的大小写更改为标题格式。每个单词的首字母大写,其余字母保持不变。短介词和连词不大写(如 'a'、'the')。

Syntax: String.toTitleCase()

Returns: String

Source: Custom n8n functionality

Examples:

1
"quick a brown FOX".toTitleCase() //=> "Quick a Brown Fox"

String.toUpperCase()#

Description: 将字符串中的所有字母转换为大写

Syntax: String.toUpperCase()

Source: JavaScript function

Examples:

1
"I'm not angry".toUpperCase() //=> "I'M NOT ANGRY"

String.trim()#

Description: 移除字符串两端的空白字符。空白字符包括换行符、制表符、空格等。

Syntax: String.trim()

Returns: String

Source: JavaScript function

Examples:

1
'   lonely   '.trim() //=> 'lonely'

String.urlDecode()#

Description: 解码 URL 编码的字符串。将 %XX 形式的字符编码替换为对应的字符。

Syntax: String.urlDecode(allChars?)

Returns: String

Source: Custom n8n functionality

Parameters:

  • allChars (Boolean) - 可选 - 是否解码属于 URI 语法的字符(例如 =?

Examples:

1
"name%3DNathan%20Automat".urlDecode() //=> "name=Nathan Automat"
1
"name%3DNathan%20Automat".urlDecode(true) //=> "name%3DNathan Automat"

String.urlEncode()#

Description: 对字符串进行编码使其可以在 URL 中使用。空格和特殊字符被替换为 %XX 形式的编码。

Syntax: String.urlEncode(allChars?)

Returns: String

Source: Custom n8n functionality

Parameters:

  • allChars (Boolean) - 可选 - 是否编码属于 URI 语法的字符(例如 =?

Examples:

1
"name=Nathan Automat".urlEncode() //=> "name%3DNathan%20Automat"
1
"name=Nathan Automat".urlEncode(true) //=> "name=Nathan%20Automat"