tuple_splittuple_splitTupleSplitTupleSplittuple_split (Operator)
Name
tuple_splittuple_splitTupleSplitTupleSplittuple_split
— Split strings into substrings using predefined separator symbol(s).
Signature
def tuple_split(string: MaybeSequence[str], separator: MaybeSequence[str]) -> Sequence[str]
def tuple_split_s(string: MaybeSequence[str], separator: MaybeSequence[str]) -> str
Description
tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
searches within the strings of the input tuple
StringStringStringStringstringValstring
for the separators defined in the input tuple
SeparatorSeparatorSeparatorSeparatorseparatorseparator
.
tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
then splits the examined strings into
the substrings divided by the separators and returns them in the
tuple SubstringsSubstringsSubstringsSubstringssubstringssubstrings
.
The behavior depends on the length of the input tuples:
-
SeparatorSeparatorSeparatorSeparatorseparatorseparator
contains only one string:
Every string in StringStringStringStringstringValstring
is split up according to the
separator symbols in SeparatorSeparatorSeparatorSeparatorseparatorseparator
.
E.g., StringStringStringStringstringValstring
= ['alpha:1', 'beta:2', 'gamma:3']["alpha:1", "beta:2", "gamma:3"]["alpha:1", "beta:2", "gamma:3"]["alpha:1", "beta:2", "gamma:3"]["alpha:1", "beta:2", "gamma:3"]["alpha:1", "beta:2", "gamma:3"]
and SeparatorSeparatorSeparatorSeparatorseparatorseparator
= ['a:']["a:"]["a:"]["a:"]["a:"]["a:"].
In this case, the operator returns the tuple SubstringsSubstringsSubstringsSubstringssubstringssubstrings
=
['lph', '1', 'bet', '2', 'g', 'mm', '3']["lph", "1", "bet", "2", "g", "mm", "3"]["lph", "1", "bet", "2", "g", "mm", "3"]["lph", "1", "bet", "2", "g", "mm", "3"]["lph", "1", "bet", "2", "g", "mm", "3"]["lph", "1", "bet", "2", "g", "mm", "3"].
-
StringStringStringStringstringValstring
contains only one string:
The single string is split up for every element in SeparatorSeparatorSeparatorSeparatorseparatorseparator
.
E.g., StringStringStringStringstringValstring
= ['alpha:1 beta:2 gamma:3']["alpha:1 beta:2 gamma:3"]["alpha:1 beta:2 gamma:3"]["alpha:1 beta:2 gamma:3"]["alpha:1 beta:2 gamma:3"]["alpha:1 beta:2 gamma:3"] and
SeparatorSeparatorSeparatorSeparatorseparatorseparator
= [':', '123'][":", "123"][":", "123"][":", "123"][":", "123"][":", "123"]. In this case, the output
tuple SubstringsSubstringsSubstringsSubstringssubstringssubstrings
will comprise the substrings
'alpha'"alpha""alpha""alpha""alpha""alpha", '1'"1""1""1""1""1", 'beta'"beta""beta""beta""beta""beta", '2'"2""2""2""2""2",
'gamma'"gamma""gamma""gamma""gamma""gamma", and '3'"3""3""3""3""3", as the result of splitting the string
of StringStringStringStringstringValstring
according to the first element of SeparatorSeparatorSeparatorSeparatorseparatorseparator
(':'":"":"":"":"":") as well as 'alpha:'"alpha:""alpha:""alpha:""alpha:""alpha:", 'beta:'"beta:""beta:""beta:""beta:""beta:", and
'gamma:'"gamma:""gamma:""gamma:""gamma:""gamma:" as the result of splitting according to the second
element of SeparatorSeparatorSeparatorSeparatorseparatorseparator
('123'"123""123""123""123""123").
-
Both tuples consist of the same amount of strings:
The search is done elementwise.
I.e., tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
will split the first string of StringStringStringStringstringValstring
according to the separator symbols in the first element of
SeparatorSeparatorSeparatorSeparatorseparatorseparator
, the second string of StringStringStringStringstringValstring
according to the
separator symbols in the second element of SeparatorSeparatorSeparatorSeparatorseparatorseparator
and so on.
-
Either or both of the input tuples are empty:
An empty tuple is returned.
Notes to SeparatorSeparatorSeparatorSeparatorseparatorseparator
:
If an element of SeparatorSeparatorSeparatorSeparatorseparatorseparator
contains more than one character,
each character defines a separator (see the example given above).
Subsequent occurrences of SeparatorSeparatorSeparatorSeparatorseparatorseparator
in StringStringStringStringstringValstring
are
treated as one separator.
Separators at the beginning and the end of StringStringStringStringstringValstring
will not
result in an empty string.
Please consider, both input tuples (StringStringStringStringstringValstring
and SeparatorSeparatorSeparatorSeparatorseparatorseparator
)
may only consist of strings. Otherwise tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
returns an error.
If both input tuples contain more than one element and the number of
elements differs for the input tuples, tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
returns an error.
Unicode code points versus bytes
The split characters are interpreted as Unicode code points. One Unicode
code point may be composed of multiple bytes in the UTF-8 string.
If the split characters should be handled as raw bytes of the string, this
operator can be switched to byte mode with
set_system('tsp_tuple_string_operator_mode','byte')set_system("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")SetSystem("tsp_tuple_string_operator_mode","byte")set_system("tsp_tuple_string_operator_mode","byte")
.
If 'filename_encoding'"filename_encoding""filename_encoding""filename_encoding""filename_encoding""filename_encoding" is set to 'locale'"locale""locale""locale""locale""locale" (legacy), this
operator always uses the byte mode.
For general information about string operations see
Tuple / String Operations.
HDevelop In-line Operation
HDevelop provides an in-line operation for tuple_splittuple_splitTupleSplitTupleSplitTupleSplittuple_split
,
which can be used in an expression in the following syntax:
Substrings := split(String, Separator)
Execution Information
- Multithreading type: independent (runs in parallel even with exclusive operators).
- Multithreading scope: global (may be called from any thread).
- Processed without parallelization.
Parameters
StringStringStringStringstringValstring
(input_control) string(-array) →
HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Input tuple with string(s) to split.
SeparatorSeparatorSeparatorSeparatorseparatorseparator
(input_control) string(-array) →
HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Input tuple with separator symbol(s).
SubstringsSubstringsSubstringsSubstringssubstringssubstrings
(output_control) string(-array) →
HTupleSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Substrings after splitting the input strings.
Alternatives
tuple_strstrtuple_strstrTupleStrstrTupleStrstrTupleStrstrtuple_strstr
,
tuple_strrstrtuple_strrstrTupleStrrstrTupleStrrstrTupleStrrstrtuple_strrstr
,
tuple_strchrtuple_strchrTupleStrchrTupleStrchrTupleStrchrtuple_strchr
,
tuple_strrchrtuple_strrchrTupleStrrchrTupleStrrchrTupleStrrchrtuple_strrchr
,
tuple_strlentuple_strlenTupleStrlenTupleStrlenTupleStrlentuple_strlen
,
tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstNTupleStrFirstNtuple_str_first_n
,
tuple_str_last_ntuple_str_last_nTupleStrLastNTupleStrLastNTupleStrLastNtuple_str_last_n
,
tuple_environmenttuple_environmentTupleEnvironmentTupleEnvironmentTupleEnvironmenttuple_environment
Module
Foundation