partExtraction of characters from stringsCalling Sequence[strings_out] = part(strings_in, v)Argumentsstrings_ina character string or matrix of character string.v
a vector of integer values containing the indices of characters to be extracted.
$ is accepted and means length(strings_in).
strings_outa character string or matrix of character string.Description
This function extracts characters from strings. The characters to be
extracted are referred to by their indices contained in v.
strings_out is filled with whitespace characters when indices
are beyond the input string's length.
v may contain $ symbol which stands for the
length of string_in.
Examples ['a' 'a' 'a']
part(['a', 'abc', 'abcd'], [1, 1]) // => ['aa' 'aa' 'aa']
part(['a', 'abc', 'abcd'], [1, 1, 2]) // => ['aa' 'aab' 'aab']
// Repeating a character N times:
N = 10; part('-', ones(1:N)) // => '----------'
// Repeating a pattern N times:
N = 6; pat = '- ';
part(pat, ones(1:N).*.(1:length(pat))) // => '- - - - - - '
// Using $ = implicit length of strings:
// 1)
part(['a string' 'another longer one'], $-2:$ ) // => [ 'ing' 'one']
// 2) Another implementation for strrev():
part('Hello world', $:-1:1) // => 'dlrow olleH'
// 3) With unranging $:
part('Hello world', [ $ 4:5 ]) // => 'dlo'
// 4) Mixing scalar or unrangin $ with ranging ones is not possible:
part("Hello", [ 1 $-1:$ $ ]) // => error
]]>See Also
string
strsplit
length
History5.5.0$ standing for length(input_strings) is now accepted in indices of selected characters