-
Notifications
You must be signed in to change notification settings - Fork 6
String Functions (StringUtils.xml)
This provides a few extension methods for working with strings. All functions treat strings as Unicode so can used with all the string types.
As Alteryx represents Dates, Times and DateTimes as strings they can also be used on those types.
All functions will be added to the String category in the function list.
Unit tests for all these functions in StringUtils.Test folder.
Syntax: FINDSTRINGLAST(Haystack, Needle)
Examples:
-
FINDSTRINGLAST('Hello World', 'World')
returns6
-
FINDSTRINGLAST('Hello World', NULL())
returns0
-
FINDSTRINGLAST('This is some text', 'World')
returns-1
Gets the index of the last Needle
in the Haystack
string. If not found will return -1
.
- Return index starts at 0.
Syntax: LEFTPART(Text, Delimiter)
Examples:
-
LEFTPART('Hello World', ' ')
returns'Hello'
-
LEFTPART('Hello', ' ')
returns'Hello'
-
LEFTPART('This is some text', ' is ')
returns'This'
Gets the part of Text
before the Delimiter
.
- The
Delimiter
can be longer than a single character. - If
Text
isNULL
, then the function will returnNULL
. - If
Delimiter
isNULL
or an empty string, then theText
value will be returned. - If
Delimiter
is not found within theText
, then the result will be theText
value.
Syntax: RIGHTPART(Text, Delimiter)
Examples:
-
RIGHTPART('Hello World', ' ')
returns'World'
-
RIGHTPART('Hello', ' ')
returns'Hello'
-
RIGHTPART('This is some text', ' is ')
returns'some text'
Gets the part of Text
after the Delimiter
.
- The
Delimiter
can be longer than a single character. - If
Text
isNULL
, then the function will returnNULL
. - If
Delimiter
isNULL
or an empty string, then theText
value will be returned. - If
Delimiter
is not found within theText
, then the result will be theText
value.
C++ Function - Split
Syntax: SPLIT(Text, Delimiter, Index)
Examples:
-
SPLIT('Hello World', ' ', 1)
returns'Hello'
-
SPLIT('Hello', ' ', 1)
returns'Hello'
-
SPLIT('Hello World', ' ', 3)
returnsNULL
Splits Text
into an array and then returns the specified index (first element is index 1)
- If the delimiter is more than one character, then each character is used as a delimiter.
- There is no support for " blocks containing delimiters.
- Repeated delimiters will result in an empty string value in the array.
- If the index is greater than the array length, then the result is
NULL
. - If
Text
isNULL
, then the function will returnNULL
.
The following functions have been added to Alteryx in version 10. They are still contained within the StringUtils.xml but commented out. Should you wish to use these functions just uncomment the sections in the XML.
Syntax: CONTAINS(Text, Target)
Examples:
-
CONTAINS('Hello World', ' ')
returnsTRUE
-
CONTAINS('Hello World', ',')
returnsFALSE
Returns TRUE
if Target
is contained in Text
.
- If both
Text
andTarget
areNULL
, returns true. - If
Text
isNULL
andTarget
is not, then the function will return false. - If
Target
isNULL
or an empty string, andText
is not, returns true.
Syntax: STARTSWITH(Text, Target)
Examples:
-
STARTSWITH('Hello World', 'Hello')
returnsTRUE
-
STARTSWITH('Hello World', 'World')
returnsFALSE
Returns TRUE
if Text
starts with Target
.
- If both
Text
andTarget
areNULL
, returns true. - If
Text
isNULL
andTarget
is not, then the function will return false. - If
Target
isNULL
or an empty string, andText
is not, returns true.
Syntax: ENDSWITH(Text, Target)
Examples:
-
ENDSWITH('Hello World', 'World')
returnsTRUE
-
ENDSWITH('Hello World', 'Hello')
returnsFALSE
Returns TRUE
if Text
ends with Target
.
- If both
Text
andTarget
areNULL
, returns true. - If
Text
isNULL
andTarget
is not, then the function will return false. - If
Target
isNULL
or an empty string, andText
is not, returns true.
Syntax: TOROMAN(Value)
Examples:
-
TOROMAN(10)
returnsX
Returns the Roman Numeral representation of a number. Valid inputs from 1 to 5000.
Syntax: FROMROMAN(RomanNumerals)
Examples:
-
FROMROMAN('X')
returns10
Returns numeric value of a the Roman Numeral. Only tested to 5000, but should cope with a longer list of Ms!
Syntax: RANDOMSTRING()
Creates a random string from a template
- RandomIPAddress: Creates a random IP address, can be contrained by a CIDR range
- RandomItem: Picks a random item from the list of parameters