Skip to main content

工作流字符串函数

Designer Cloud 中,字符串函数对文本数据执行操作。使用字符串函数清理数据、将数据转换为其它格式或大小写、对数据进行度量计算或执行其它操作。字符串函数只能用于字符串数据类型。

注意

Not all functions are supported between Standard mode and Cloud Native mode tools. For a list of supported functions, go to the respective Standard mode and Could Native mode function lists found on the Formula tool page.

包含

Contains(String, Target, CaseInsensitive=1):在一个字符串中搜索某一字符串的匹配项。如果字符串 (String) 包含目标 (Target),则返回 True,否则返回 False。

示例

Contains('123ABC', 'ABC') 返回 True。

Contains('123ABC', 'abc') 返回 True。

Contains('123ABC', 'abc', 0) 返回 False。

CountWords

CountWords(string):返回指定字符串中的单词计数。单词由空格分隔的字符定义。

示例

CountWords("Basic Variables Households")返回 3。

CountWords("Basic Variables Age:Female (Pop)Age 1") 返回 5。

DecomposeUnicodeForMatch

DecomposeUnicodeForMatch(String): Removes accents and expands compound characters while converting to a narrow string. All accents and other decorations are removed.

重要

This function is useful for matching only. It is not considered a normalized string.

The function is not designed for use with non-western character sets like Japanese. You should avoid using this function on strings that might contain wide characters and note that wide characters are converted to '?'.

Example

DecomposeUnicodeForMatch("Prénoms français")returns prenoms francais.

EndsWith

EndsWith(String, Target, CaseInsensitive=1):检查字符串是否以特定的字符串结尾。如果 (String) 以 (Target) 结尾,则返回 True;否则,返回 False。默认行为不区分大小写。

示例

EndsWith('123ABC', 'ABC')返回 True。

EndsWith('123ABC', 'abc')返回 True。

EndsWith('123ABC', 'abc', 0)返回 False。

FindNth

FindNth(Initial String, Target, Instance): Finds the instance (nth occurrence) of a target string in the initial string and returns the 0-indexed position of the instance. The function is case-sensitive and doesn’t accept negative parameters.

重要

In Cloud Native mode, Target and Instance must be static literal values.

Example

FindNth("Hello World","o",2)returns 7. The function finds the 2nd instance of "o" in the provided string and returns the 0-indexed position, which in this case is 7.

FindNth("Hello World","World",1)returns 6. The function finds the 1st instance of "World" in the provided string and returns the 0-indexed position of the first character, which in this case is 6.

FindNth("Hello World","o",1.8)returns 7. The function finds the 2nd instance (rounds 1.8 to the nearest integer) of "o" in the provided string and returns the 0-indexed position of the 2nd character, which in this case is 7.

FindNth("Hello World","world",1)returns -1. The function finds the 1st instance of "world" in the provided string and returns the 0-indexed position of the first character, which in this case is -1 (match not found due to case sensitivity).

FindNth("Hello World","l",0)returns -1. The function finds the 0th instance of "l" in the provided string and returns the 0-indexed position, which in this case is -1 (not found because the 0th position doesn't exist).

FindNth("Hello World","l",-1)returns -1. Negative parameters are not applicable, so the function returns -1 (not found).

FindNth("Hello World", Null(), 1)returns -1. Null and empty are not found.

FindNth(Hello world, "l", 1)returns an error. The function requires that the first 2 parameters are strings.

FindString

FindString 函数区分大小写。

FindString(String,Target):搜索一个字符串 (String) 中特定字符串 (Target) 的匹配项,并返回特定字符串在字符串中的数字位置。

返回字符串 (String) 中首个目标 (Target) 的索引(从 0 开始)。如果不存在匹配项,则返回 -1。

示例

FindString([Name], "John")在字符串以 John 开头时返回 0,否则返回 -1

IF (FINDSTRING([Name], "John") =0) THEN "John Smith" ELSE "Other" ENDIF 在字符串包含 John 时返回 John Smith,不包含时返回 Other

GetLeft

GetLeft(String, Delimiter): Returns the left part of the provided (String) until the first instance of the specified 1 or more (Delimiter). In Cloud Native mode, Delimiter must be a static literal value.

注意

The Delimiter operator is case-sensitive. If you specify "a" as the delimiter, the function only uses "a" as the delimiter, not "A".

Example

GetLeft("Automated Analytics for All", " ") returns "Automated".

GetLeft("Enable fast, confident decisions across the enterprise.", ",") returns "Enable fast".

GetPart

GetPart(String, Delimiter, Index): Uses the specified 1 or more (Delimiters) to divide (String) into substrings, and returns the substring in the position that is specified in (Index). In Cloud Native mode, Delimiter must be a static literal value.

This function uses a 0-based index. For example, if Index is 2, the function returns the string from the position in index 2, which is the third substring.

注意

The Delimiter operator is case-sensitive. If you specify "a" as the delimiter, the function only uses "a" as the delimiter, not "A".

Example

GetPart("Automated Analytics for All", " ", 1) returns "Analytics".

GetPart("Automated Analytics for All", " ", 0) returns "Automated".

GetPart("Enable fast, confident decisions across the enterprise.", ", ", 5) returns "across". Note that this example uses 2 delimiters—a comma and a space. The function splits the string when it encounters either delimiter.

GetPart("January 1, 2023", " ", 2) returns "2023".

GetRight

GetRight(String, Delimiter): Returns the right part of the provided (String) after the first instance of the specified 1 or more (Delimiters). In Cloud Native mode, Delimiter must be a static literal value.

注意

The Delimiter operator is case-sensitive. If you specify "a" as the delimiter, the function only uses "a" as the delimiter, not "A".

Example

GetRight("Automated Analytics for All", " ")returns "Analytics for All".

GetRight("Enable fast, confident decisions across the enterprise.", ",") returns " confident decisions across the enterprise." (note the space beforeconfident in the return).

GetWord

GetWord(string, n):返回字符串中的第 N 个(索引从 0 开始)单词。字指的是由空格分隔的字符集合。索引从 0 开始,表示第一个字的位置位于 0。

示例

GetWord("Basic Variables Households", 0)返回“Basic”。

GetWord("Basic Variables Households", 1)返回“Variables”。

Left

Left(String, len):返回字符串 (String) 中最左边长度为 (len) 的字符。如果 len 小于 0 或大于字符串 (String) 的长度,则字符串保持不变。

示例

Left("92688", 3) 返回值“926”。

Length

Length(String):返回字符串 (String) 的长度。

示例

Length("92688") 返回值 5。

LowerCase

LowerCase(String):将字符串转换为小写。

示例

LowerCase("M1P 1G6")返回"m1p 1g6"。

MD5_ASCII

MD5_ASCII(String): Calculates the MD5 hash of the string. The string is expected to be only narrow characters. Wide characters are converted to '?' before computing the hash. Use for String types. You should avoid using this function on strings that might contain wide characters.

MD5_UNICODE

MD5_UNICODE(String): Calculates the MD5 hash of the string stored as UTF-16.

MD5_UTF8

MD5_UTF8(String): Calculates the MD5 hash of the string stored as UTF-8.

Example

Md5_Ascii("Lá"), stored as Latin1, it takes 2 bytes, 4C E1. The function computes the MD5 of the bytes, giving the result "0c0ee86cc87d87125ad8923562be952e".

Md5_Ascii("Lá ☢"), the ☢ character, being wide, is replaced with a '?', so it's as if you were computing Md5_Ascii("Lá?"). That is stored as Latin1 in 3 bytes, 4C E1 3F. The function computes the MD5 of the bytes, giving the result "a5a308ab19acf900efea8fc7b5b77b4d".

Md5_Unicode("Lá"), stored as UTF-16, it takes 4 bytes, 4C 00 E1 00. The function computes the MD5 of the bytes, giving the result "aa9969dfcca04249842cc457e5b3dd01".

Md5_Unicode("Lá ☢"), when stored as UTF-16 takes 8 bytes, 4C 00 E1 00 3C D8 C8 DF. The function computes the MD5 of the bytes, giving the result: "7c4762d93572dd02a8a405232e966b18".

Md5_Utf8("Lá"), stored as UTF-8, it takes 3 bytes, 4C C3 A1. The function computes the MD5 of the bytes, giving the result "68f00289dc3be140b1dfd4e031d733f1".

Md5_Utf8("Lá ☢"), when stored as UTF-8 takes 7 bytes, 4C C3 A1 F0 9F 8F 88. The function computes the MD5 of the bytes, giving the result "383fc0355db728a2078ce41a2ab6211b".

PadLeft

PadLeft(String, len, char):将指定的字符向左填充字符串,直到字符串达到指定长度为止。如果用于填充的字符 (char) 超过一个字符,则仅使用第一个字符。

示例

PadLeft("M", 4, "x")返回“xxxM”。

PadRight

PadRight(String, len, char):将指定的字符向右填充字符串,直到字符串达到指定长度为止。如果用于填充的字符 (char) 超过一个字符,则仅使用第一个字符。

示例

PadRight("M", 4, "x")返回“Mxxx”。

REGEX_CountMatches

REGEX_CountMatches(String,pattern,icase): Returns the count of matches within the string to the pattern.

icase is an optional parameter. When specified, the case must match. By default icase=1 (meaning ignore case). If set to 0, the case must match.

REGEX_Match

REGEX_Match(String,pattern,icase):搜索字符串中正则表达式的匹配项。

判断字符串是否从第一个字符到最后一个字符与模式匹配。

  • 如果匹配不一定始于字符串之首,则在模式开头加上 “.*”。

  • 如果匹配项不一定在字符串之尾,则在模式结尾加上 “.*”。

有关如何正确构建正则表达式的详细信息,请参阅 Boost Regex Perl 正则表达式语法页面。

icase 是可选参数。使用了此参数时,大小写必须匹配。默认情况下,icase=1 表示忽略大小写。如果设置为 0,则大小写必须匹配。

示例

REGEX_Match("123-45-6789", "\d{3}-\d{2}-\d{4}")返回 -1 (True)。

REGEX_Replace

REGEX_Replace(String, pattern, replace, icase):返回 RegEx 查找模式产生的字符串,然后替换字符串。

replace 参数可以是指定值(如下所示),也可以是一个标记的组(如“$1”)。确保标记的组用双引号括起来。

icase 是可选参数。使用了此参数时,大小写必须匹配。

  • 默认情况下 icase=1,表示忽略大小写。

  • 如果设置为 0,则大小写必须匹配。

示例

REGEX_Replace("Don't reveal your Social Security number, 123-45-6789","\d{3}-\d{2}-\d{4}", "CLASSIFIED") 返回“Don't reveal your Social Security number, CLASSIFIED”。

REGEX_Replace("Change all domain names from alteryx@Alteryx.com","@.*\.", "@extendthereach.") 返回“Change all domain names from alteryx@extendthereach.com”。

REGEX_Replace("25 test","(\d+)\s.*","$1") 返回 25。

替换

Replace(String, Target, Replacement):使用字符串 (Replacement) 替换出现的每一个字符串 (Target),再返回字符串 (String)。

示例

Replace("Good judgment comes from experience", "experience", "awareness") 返回“Good judgement comes from awareness”

替换字符

ReplaceChar(String, y, z):将每个出现的字符 (y) 替换为字符 (z) 后返回字符串 (String)。如果替换字符 (z) 具有一个以上的字符,则仅使用第一个字符。如果 (z) 为空,则每个与 (y) 中的任何一个字符匹配的字符 (String) 将被移除。

示例

ReplaceChar("abcdefb", "b", "_")返回“a_cdef_”。

ReplaceChar("@a#b%c", "@,#,%", "_")返回“_a_b_c”。

ReplaceFirst

ReplaceFirst(String, Target, Replacement):使用字符串 (Replacement) 替换字符串 (Target) 的第一个匹配项后,返回字符串 (String)。

示例

ReplaceFirst("abcdefb", "b", "_")返回“a_cdefb”。

ReverseString

ReverseString(String):反转字符串中的所有字符。

示例

ReverseString("abcdefb") 返回“bfedcba”。

StartsWith

StartsWith(String, Target, CaseInsensitive=1):检查字符串是否以特定的字符串开头。如果字符串 String 以特定字符串 Target 开头,则返回 True,否则返回 False。

示例

StartsWith('ABC123', 'ABC')返回 True。

StartsWith('ABC123', 'abc')返回 True。

StartsWith('ABC123', 'abc', 0)返回 False。

STRCSPN

STRCSPN(String, y): Returns the length of the initial segment of the string (String) consisting of charactersnotin the string (y).

Example

STRCSPN("Bob's Amaco", "~!@#$%^&*'()")returns 3. This is a useful test to make sure there is no punctuation in the string.

StripQuotes

StripQuotes(String):移除字符串结尾的一组成对的引号或单引号。

示例

  • StripQuotes("Hello there") 返回 Hello there

  • StripQuotes("'Hello there,' she said.") 返回 'Hello there,' she said.

  • StripQuotes('"Hello there," she said.') 返回 "Hello there," she said.

STRSPN

STRSPN(String, y): Returns the length of the initial segment of the string (String) consisting of characters in the string (y).

Example

STRSPN("3034408896x105", "0123456789") returns 10. This is a useful test to make sure a string consists of a set of characters.

Substring

Substring(String, start, length):返回字符串 (String) 从 (start) 位置开始提取长度等于 (length) 的子字符串(如果提供了长度)。

示例

Substring("949-222-4356", 4, 8) 返回“222-4356”。

Substring("949-222-4356", 4, 6) 返回“222-43”。

Substring("949-222-4356", 4) 返回“222-4356”。

TitleCase

TitleCase(String):将字符串转换为词首字母大写。

示例

TitleCase("john smith")返回 “John Smith”。

Trim

Trim(String, y):移除字符串(String)首部和尾部出现的 y 中的任意字符。Y 是可选项,默认为去掉空格。提示:在 TRIM 函数示例中,指定的字符将被去掉。字符顺序不重要。

示例

Trim("!see instructions!!!", "!") 返回“see instructions”。

Trim(" Test123 ") 返回“Test123”。

TrimLeft

TrimLeft(String, y):移除字符串 (String) 开头出现的字符串 (y) 中的字符。Y 是可选项,默认为去掉空格。

示例

TrimLeft("** special invitation ", " *") 返回“special invitation”。

TrimRight

TrimRight(String, y):移除字符串 (String) 末尾出现的字符串 (y) 中的字符。Y 是可选项,默认为去掉空格。

示例

TrimRight("John Smith ")返回 “John Smith”。

TrimRight("John Smith**","*")返回 “John Smith”。

当你输入要修剪的字符串时,TRIM 函数不遵守字符的顺序。它将字符串视为“列表”。因此,它将修剪列表中的所有字符。如果您要替换字符串,请在表达式中使用REPLACE 函数或 REGEX 函数。

Uppercase

Uppercase(String): 将字符串转换为大写。

示例

Uppercase("John Smith") 返回“JOHN SMITH”。

UuidCreate

UuidCreate(): Creates a unique identifier.

Example

UuidCreate()returns a unique value such as ba131836-1ba3-4d42-8f7e-b81a99c2e838.