Skip to content

tuple_str_first_nTupleStrFirstNTupleStrFirstNtuple_str_first_ntuple_str_first_nšŸ”—

Short descriptionšŸ”—

tuple_str_first_nTupleStrFirstNTupleStrFirstNtuple_str_first_ntuple_str_first_n — Cut the first characters up to position ā€œnā€ out of a string tuple.

SignaturešŸ”—

tuple_str_first_n( string String, number Position, out string Substring )void TupleStrFirstN( const HTuple& String, const HTuple& Position, HTuple* Substring )static void HOperatorSet.TupleStrFirstN( HTuple stringVal, HTuple position, out HTuple substring )def tuple_str_first_n( string: MaybeSequence[str], position: MaybeSequence[Union[float, int]] ) -> Sequence[str]

def tuple_str_first_n_s( string: MaybeSequence[str], position: MaybeSequence[Union[float, int]] ) -> strHerror 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 )

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

HTuple HTuple.TupleStrFirstN( HTuple position )

DescriptionšŸ”—

tuple_str_first_nTupleStrFirstN cuts the first characters up to position ā€œnā€ out of each string of the input tuple StringstringValstring and returns them as new strings in the output tuple Substringsubstringsubstring (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 Positionpositionposition. If Positionpositionposition only contains one element, this element contains the number ā€œnā€. If StringstringValstring and Positionpositionposition have got the same number of elements, the first element of Positionpositionposition determines the position ā€œnā€ for the first string of StringstringValstring, the second element of Positionpositionposition does so for the second string of StringstringValstring and so on. If Positionpositionposition contains more than one element and StringstringValstring contains only one string, tuple_str_first_nTupleStrFirstN cuts more than one substrings out of this string. The elements of Positionpositionposition 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_nTupleStrFirstN returns an error.

If both input tuples are empty, the operator returns an empty tuple. Similarly, if StringstringValstring is empty and Positionpositionposition is not, the operator returns an empty tuple. In contrast, if Positionpositionposition is empty and StringstringValstring 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'). If 'filename_encoding'"filename_encoding" is set to '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_nTupleStrFirstN, which can be used in an expression in the following syntax:

Substring := str_firstn(String, Position)

Execution informationšŸ”—

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

ParametersšŸ”—

StringstringValstring (input_control) string(-array) → (string)HTuple (HString)HTuple (string)MaybeSequence[str]Htuple (char*)

Input tuple with string(s) to examine.

Positionpositionposition (input_control) number(-array) → (integer / real)HTuple (Hlong / double)HTuple (int / long / double)MaybeSequence[Union[float, int]]Htuple (Hlong / double)

Input tuple with position(s) ā€œnā€.

Substringsubstringsubstring (output_control) string(-array) → (string)HTuple (HString)HTuple (string)Sequence[str]Htuple (char*)

The first characters of the string(s) up to position ā€œnā€.

Combinations with other operatorsšŸ”—

Combinations

Alternatives

tuple_str_last_nTupleStrLastN, tuple_substrTupleSubstr, tuple_strstrTupleStrstr, tuple_strrstrTupleStrrstr, tuple_strlenTupleStrlen, tuple_strchrTupleStrchr, tuple_strrchrTupleStrrchr, tuple_splitTupleSplit, tuple_environmentTupleEnvironment

ModulešŸ”—

Foundation