tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstN (Operator)


tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstN — Cut the first characters up to position “n” out of a string tuple.


tuple_str_first_n( : : String, Position : Substring)

Herror tuple_str_first_n(const char* String, const Hlong Position, char* Substring)

Herror T_tuple_str_first_n(const Htuple String, const Htuple Position, Htuple* Substring)

void TupleStrFirstN(const HTuple& String, const HTuple& Position, HTuple* Substring)

HTuple HTuple::TupleStrFirstN(const HTuple& Position) const

static void HOperatorSet.TupleStrFirstN(HTuple stringVal, HTuple position, out HTuple substring)

HTuple HTuple.TupleStrFirstN(HTuple position)


tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstNTupleStrFirstN cuts the first characters up to position “n” out of each string of the input tuple StringStringStringStringstringVal and returns them as new strings in the output tuple SubstringSubstringSubstringSubstringsubstring (remark: the position within strings starts with 0 for the first character of a string). The number “n” is determined by the second input tuple PositionPositionPositionPositionposition. If PositionPositionPositionPositionposition only contains one element, this element contains the number “n”. If StringStringStringStringstringVal and PositionPositionPositionPositionposition have got the same number of elements, the first element of PositionPositionPositionPositionposition determines the position “n” for the first string of StringStringStringStringstringVal, the second element of PositionPositionPositionPositionposition does so for the second string of StringStringStringStringstringVal and so on. If PositionPositionPositionPositionposition contains more than one element and StringStringStringStringstringVal contains only one string, tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstNTupleStrFirstN cuts more than one substrings out of this string. The elements of PositionPositionPositionPositionposition then determine the lengths of these substrings. If both input tuples contain more than one element but differ in the number of elements, tuple_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstNTupleStrFirstN returns an error.

If both input tuples are empty, the operator returns an empty tuple. Similarly, if StringStringStringStringstringVal is empty and PositionPositionPositionPositionposition is not, the operator returns an empty tuple. In contrast, if PositionPositionPositionPositionposition is empty and StringStringStringStringstringVal is not, an exception is raised.

Unicode code points versus bytes

The position references Unicode code points. One Unicode code point may be composed of multiple bytes in the UTF-8 string. If the position should reference the 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"). If 'filename_encoding'"filename_encoding""filename_encoding""filename_encoding""filename_encoding" is set to '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_str_first_ntuple_str_first_nTupleStrFirstNTupleStrFirstNTupleStrFirstN, which can be used in an expression in the following syntax:

Substring := str_firstn(String, Position)

Execution Information


StringStringStringStringstringVal (input_control)  string(-array) HTupleHTupleHtuple (string) (string) (HString) (char*)

Input tuple with string(s) to examine.

PositionPositionPositionPositionposition (input_control)  number(-array) HTupleHTupleHtuple (integer / real) (int / long / double) (Hlong / double) (Hlong / double)

Input tuple with position(s) “n”.

SubstringSubstringSubstringSubstringsubstring (output_control)  string(-array) HTupleHTupleHtuple (string) (string) (HString) (char*)

The first characters of the string(s) up to position “n”.


tuple_str_last_ntuple_str_last_nTupleStrLastNTupleStrLastNTupleStrLastN, tuple_substrtuple_substrTupleSubstrTupleSubstrTupleSubstr, tuple_strstrtuple_strstrTupleStrstrTupleStrstrTupleStrstr, tuple_strrstrtuple_strrstrTupleStrrstrTupleStrrstrTupleStrrstr, tuple_strlentuple_strlenTupleStrlenTupleStrlenTupleStrlen, tuple_strchrtuple_strchrTupleStrchrTupleStrchrTupleStrchr, tuple_strrchrtuple_strrchrTupleStrrchrTupleStrrchrTupleStrrchr, tuple_splittuple_splitTupleSplitTupleSplitTupleSplit, tuple_environmenttuple_environmentTupleEnvironmentTupleEnvironmentTupleEnvironment