ce9e711a2239b7b2182e7711d980bf14f3a48f0b
[scilab.git] / scilab / modules / string / help / en_US / strspn.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) INRIA -
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  * Copyright (C) 2020 - Samuel GOUGEON
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  -->
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17           xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
18           xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
19           xml:id="strspn" xml:lang="en">
20     <refnamediv>
21         <refname>strspn</refname>
22         <refpurpose>
23             lengths of the beginning of strings as long as characters are among those allowed
24         </refpurpose>
25     </refnamediv>
26     <refsynopsisdiv>
27         <title>Syntax</title>
28         <synopsis>headsLengths = strspn(Strings, allowedChars)</synopsis>
29     </refsynopsisdiv>
30     <refsection>
31         <title>Arguments</title>
32         <variablelist>
33             <varlistentry>
34                 <term>Strings, allowedChars, headsLengths</term>
35                 <listitem>
36                     <para>
37                         Matrices of strings, of identical dimensions.
38                         <varname>allowedChars</varname> can be a scalar string.
39                         It is then used for all <varname>Strings</varname> components.
40                     </para>
41                 </listitem>
42             </varlistentry>
43         </variablelist>
44     </refsection>
45     <refsection>
46         <title>Description</title>
47         <para>
48             <literal>headsLengths = strspn(Strings, allowedChars)</literal> returns the length of the initial
49             portion of <varname>Strings</varname> which consists only of characters that are part of
50             <varname>allowedChars</varname>.
51         </para>
52     </refsection>
53     <refsection>
54         <title>Examples</title>
55         <programlisting role="example"><![CDATA[
56 allowed = "0":"9"
57 strspn("129th or the 130th", allowed)
58
59 t = ["characters" "matrix" ; "text" "strings"]
60 allowed = "a":"s"
61 strspn(t, allowed)
62
63 allowed = ["a":"j", "a":"u" ; "d":"u", "g":"v"]
64 strspn(t, allowed)
65      ]]></programlisting>
66         <screen><![CDATA[
67 --> allowed = "0":"9"
68  allowed  =
69   "0123456789"
70
71 --> strspn("129th or the 130th", allowed)
72  ans  =
73    3.
74
75
76 --> t = ["characters" "matrix" ; "text" "strings"]
77  t  =
78   "characters"  "matrix"
79   "text"        "strings"
80
81 --> allowed = "a":"s"
82  allowed  =
83   "abcdefghijklmnopqrs"
84 --> strspn(t, allowed)
85  ans  =
86    6.   2.
87    0.   1.
88
89 --> allowed = ["a":"j", "a":"u" ; "d":"u", "g":"v"]
90  allowed  =
91   "abcdefghij"          "abcdefghijklmnopqrstu"
92   "defghijklmnopqrstu"  "ghijklmnopqrstuv"
93
94 --> strspn(t, allowed)
95  ans  =
96    3.   5.
97    2.   7.
98 ]]></screen>
99         <para>
100             With UTF-8 extended characters:
101         </para>
102         <programlisting role="example"><![CDATA[
103 t = "Να αμφιβάλλετε τα πάντα ή να μην αμφιβάλλετε τίποτα: " + ..
104     "δύο ίσοι τρόποι αποφυγής σκέψης.";
105 t = matrix(strsplit(t," "), 2,-1)
106 allowed = "Ναβγδεϵζηθικλμνξοπρστυφϕχψωϐϑϰϱςϖ";
107 strspn(t, allowed)
108  ]]></programlisting>
109         <screen><![CDATA[
110 --> t = matrix(strsplit(t," "), 2,-1)
111  t  =
112   "Να"           "τα"     "ή"   "μην"          "τίποτα:"  "ίσοι"    "αποφυγής"
113   "αμφιβάλλετε"  "πάντα"  "να"  "αμφιβάλλετε"  "δύο"      "τρόποι"  "σκέψης."
114
115 --> allowed = "Ναβγδεϵζηθικλμνξοπρστυφϕχψωϐϑϰϱςϖ";
116 --> strspn(t, allowed)
117  ans  =
118    2.   2.   0.   3.   1.   0.   6.
119    5.   1.   2.   5.   1.   2.   2.
120 ]]></screen>
121     </refsection>
122     <refsection role="see also">
123         <title>See also</title>
124         <simplelist type="inline">
125             <member>
126                 <link linkend="strcspn">strcspn</link>
127             </member>
128             <member>
129                 <link linkend="strncpy">strncpy</link>
130             </member>
131             <member>
132                 <link linkend="part">part</link>
133             </member>
134         </simplelist>
135     </refsection>
136 </refentry>