1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) INRIA -
* Copyright (C) Samuel GOUGEON - 2013 : $ is now supported. More examples.
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
-->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xml:id="part" xml:lang="en">
<refnamediv>
<refname>part</refname>
<refpurpose>Extraction of characters from strings</refpurpose>
</refnamediv>
<refsynopsisdiv>
<title>Calling Sequence</title>
<synopsis>[strings_out] = part(strings_in, v)</synopsis>
</refsynopsisdiv>
<refsection>
<title>Arguments</title>
<variablelist>
<varlistentry>
<term>strings_in</term>
<listitem>
<para>a character string or matrix of character string.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>v</term>
<listitem>
<para>
a vector of integer values containing the indices of characters to be extracted.
<literal>$</literal> is accepted and means length(strings_in).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term>strings_out</term>
<listitem>
<para>a character string or matrix of character string.</para>
</listitem>
</varlistentry>
</variablelist>
</refsection>
<refsection>
<title>Description</title>
<para>
This function extracts characters from strings. The characters to be
extracted are referred to by their indices contained in <literal>v</literal>.
</para>
<para>
<literal>strings_out</literal> is filled with whitespace characters when indices
are beyond the input string's length.
</para>
<para>
<literal>v</literal> may contain <literal>$</literal> symbol which stands for the
length of <literal>string_in</literal>.
</para>
</refsection>
<refsection>
<title>Examples</title>
<programlisting role="example"><![CDATA[
// Returns characters position 8 to 11
part("How to use ""part"" ?", 8:11)
// Returns characters position 2 to 4 for each element
// No characters replaced by ''
c = part(['a', 'abc', 'abcd'], 2:4)
// Returns character position 1 for each element and add characters position
// 4 to 7 of each element
c = part(['abcdefg', 'hijklmn', 'opqrstu'], [1, 4:7]);
// Returns character 4 for each element, add characters position 1 to 7 and
// add character position 4 for each element
c = part(['abcdefg', 'hijklmn', 'opqrstu'], [4, 1:7, 4]);
// Returns character position 1, add again character position 1 and
// character position 2
c=part(['a', 'abc', 'abcd'], [1, 1, 2])
part(['a', 'abc', 'abcd'], [1]) // => ['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
]]></programlisting>
</refsection>
<refsection role="see also">
<title>See Also</title>
<simplelist type="inline">
<member>
<link linkend="string">string</link>
</member>
<member>
<link linkend="strsplit">strsplit</link>
</member>
<member>
<link linkend="length">length</link>
</member>
</simplelist>
</refsection>
<refsection>
<title>History</title>
<revhistory>
<revision>
<revnumber>5.5.0</revnumber>
<revremark>
<literal>$</literal> standing for length(input_strings) is now accepted in indices of selected characters
</revremark>
</revision>
</revhistory>
</refsection>
</refentry>
|