Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 345

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Manipulating Strings - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Strings.html#Strings" title="Strings">
<link rel="prev" href="Comparing-Strings.html#Comparing-Strings" title="Comparing Strings">
<link rel="next" href="String-Conversions.html#String-Conversions" title="String Conversions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Manipulating-Strings"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="String-Conversions.html#String-Conversions">String Conversions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Comparing-Strings.html#Comparing-Strings">Comparing Strings</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Strings.html#Strings">Strings</a>
<hr>
</div>

<h3 class="section">5.5 Manipulating Strings</h3>

<p>Octave supports a wide range of functions for manipulating strings. 
Since a string is just a matrix, simple manipulations can be accomplished
using standard operators.  The following example shows how to replace
all blank characters with underscores.

<pre class="example">     quote = ...
       "First things first, but not necessarily in that order";
     quote( quote == " " ) = "_"
     &rArr; quote =
         First_things_first,_but_not_necessarily_in_that_order
</pre>
   <p>For more complex manipulations, such as searching, replacing, and
general regular expressions, the following functions come with Octave.

<!-- deblank scripts/strings/deblank.m -->
   <p><a name="doc_002ddeblank"></a>

<div class="defun">
&mdash; Function File:  <b>deblank</b> (<var>s</var>)<var><a name="index-deblank-357"></a></var><br>
<blockquote><p>Remove trailing whitespace and nulls from <var>s</var>.  If <var>s</var>
is a matrix, <var>deblank</var> trims each row to the length of longest
string.  If <var>s</var> is a cell array of strings, operate recursively on each
string element.

        <p>Examples:

     <pre class="example">          deblank ("    abc  ")
               &rArr;  "    abc"
          
          deblank ([" abc   "; "   def   "])
               &rArr;  [" abc  " ; "   def"]
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrtrim.html#doc_002dstrtrim">strtrim</a>. 
</p></blockquote></div>

<!-- strtrim scripts/strings/strtrim.m -->
   <p><a name="doc_002dstrtrim"></a>

<div class="defun">
&mdash; Function File:  <b>strtrim</b> (<var>s</var>)<var><a name="index-strtrim-358"></a></var><br>
<blockquote><p>Remove leading and trailing whitespace from <var>s</var>.  If
<var>s</var> is a matrix, <var>strtrim</var> trims each row to the length of
longest string.  If <var>s</var> is a cell array of strings, operate recursively
on each string element.  For example:

     <pre class="example">          strtrim ("    abc  ")
               &rArr;  "abc"
          
          strtrim ([" abc   "; "   def   "])
               &rArr;  ["abc  "  ; "  def"]
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002ddeblank.html#doc_002ddeblank">deblank</a>. 
</p></blockquote></div>

<!-- strtrunc scripts/strings/strtrunc.m -->
   <p><a name="doc_002dstrtrunc"></a>

<div class="defun">
&mdash; Function File:  <b>strtrunc</b> (<var>s, n</var>)<var><a name="index-strtrunc-359"></a></var><br>
<blockquote><p>Truncate the character string <var>s</var> to length <var>n</var>.  If <var>s</var>
is a character matrix, then the number of columns is adjusted. 
If <var>s</var> is a cell array of strings, then the operation is performed
on each cell element and the new cell array is returned. 
</p></blockquote></div>

<!-- findstr scripts/strings/findstr.m -->
   <p><a name="doc_002dfindstr"></a>

<div class="defun">
&mdash; Function File:  <b>findstr</b> (<var>s, t</var>)<var><a name="index-findstr-360"></a></var><br>
&mdash; Function File:  <b>findstr</b> (<var>s, t, overlap</var>)<var><a name="index-findstr-361"></a></var><br>
<blockquote><p>Return the vector of all positions in the longer of the two strings
<var>s</var> and <var>t</var> where an occurrence of the shorter of the two starts. 
If the optional argument <var>overlap</var> is true, the returned vector
can include overlapping positions (this is the default).  For example:

     <pre class="example">          findstr ("ababab", "a")
               &rArr; [1, 3, 5];
          findstr ("abababa", "aba", 0)
               &rArr; [1, 5]
</pre>
        <p><strong>Caution:</strong> <code>findstr</code> is scheduled for deprecation.  Use
<code>strfind</code> in all new code. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrfind.html#doc_002dstrfind">strfind</a>, <a href="doc_002dstrmatch.html#doc_002dstrmatch">strmatch</a>, <a href="doc_002dstrcmp.html#doc_002dstrcmp">strcmp</a>, <a href="doc_002dstrncmp.html#doc_002dstrncmp">strncmp</a>, <a href="doc_002dstrcmpi.html#doc_002dstrcmpi">strcmpi</a>, <a href="doc_002dstrncmpi.html#doc_002dstrncmpi">strncmpi</a>, <a href="doc_002dfind.html#doc_002dfind">find</a>. 
</p></blockquote></div>

<!-- strchr scripts/strings/strchr.m -->
   <p><a name="doc_002dstrchr"></a>

<div class="defun">
&mdash; Function File: <var>idx</var> = <b>strchr</b> (<var>str, chars</var>)<var><a name="index-strchr-362"></a></var><br>
&mdash; Function File: <var>idx</var> = <b>strchr</b> (<var>str, chars, n</var>)<var><a name="index-strchr-363"></a></var><br>
&mdash; Function File: <var>idx</var> = <b>strchr</b> (<var>str, chars, n, direction</var>)<var><a name="index-strchr-364"></a></var><br>
&mdash; Function File: [<var>i</var>, <var>j</var>] = <b>strchr</b> (<var><small class="dots">...</small></var>)<var><a name="index-strchr-365"></a></var><br>
<blockquote><p>Search for the string <var>str</var> for occurrences of characters from
the set <var>chars</var>.  The return value(s), as well as the <var>n</var> and
<var>direction</var> arguments behave identically as in <code>find</code>.

        <p>This will be faster than using regexp in most cases.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfind.html#doc_002dfind">find</a>. 
</p></blockquote></div>

<!-- index scripts/strings/index.m -->
   <p><a name="doc_002dindex"></a>

<div class="defun">
&mdash; Function File:  <b>index</b> (<var>s, t</var>)<var><a name="index-index-366"></a></var><br>
&mdash; Function File:  <b>index</b> (<var>s, t, direction</var>)<var><a name="index-index-367"></a></var><br>
<blockquote><p>Return the position of the first occurrence of the string <var>t</var> in the
string <var>s</var>, or 0 if no occurrence is found.  <var>s</var> may also be a
string array or cell array of strings.

        <p>For example:

     <pre class="example">          index ("Teststring", "t")
             &rArr; 4
</pre>
        <p>If <var>direction</var> is &lsquo;<samp><span class="samp">"first"</span></samp>&rsquo;, return the first element found. 
If <var>direction</var> is &lsquo;<samp><span class="samp">"last"</span></samp>&rsquo;, return the last element found.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfind.html#doc_002dfind">find</a>, <a href="doc_002drindex.html#doc_002drindex">rindex</a>. 
</p></blockquote></div>

<!-- rindex scripts/strings/rindex.m -->
   <p><a name="doc_002drindex"></a>

<div class="defun">
&mdash; Function File:  <b>rindex</b> (<var>s, t</var>)<var><a name="index-rindex-368"></a></var><br>
<blockquote><p>Return the position of the last occurrence of the character string
<var>t</var> in the character string <var>s</var>, or 0 if no occurrence is
found.  <var>s</var> may also be a string array or cell array of strings.

        <p>For example:

     <pre class="example">          rindex ("Teststring", "t")
               &rArr; 6
</pre>
        <p>The <code>rindex</code> function is equivalent to <code>index</code> with
<var>direction</var> set to &lsquo;<samp><span class="samp">"last"</span></samp>&rsquo;.

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfind.html#doc_002dfind">find</a>, <a href="doc_002dindex.html#doc_002dindex">index</a>. 
</p></blockquote></div>

<!-- strfind src/DLD-FUNCTIONS/strfind.cc -->
   <p><a name="doc_002dstrfind"></a>

<div class="defun">
&mdash; Loadable Function: <var>idx</var> = <b>strfind</b> (<var>str, pattern</var>)<var><a name="index-strfind-369"></a></var><br>
&mdash; Loadable Function: <var>idx</var> = <b>strfind</b> (<var>cellstr, pattern</var>)<var><a name="index-strfind-370"></a></var><br>
<blockquote><p>Search for <var>pattern</var> in the string <var>str</var> and return the
starting index of every such occurrence in the vector <var>idx</var>. 
If there is no such occurrence, or if <var>pattern</var> is longer
than <var>str</var>, then <var>idx</var> is the empty array <code>[]</code>.

        <p>If a cell array of strings <var>cellstr</var> is specified
then <var>idx</var> is a cell array of vectors, as specified
above.  Examples:

     <pre class="example">          strfind ("abababa", "aba")
               &rArr; [1, 3, 5]
          
          strfind ({"abababa", "bebebe", "ab"}, "aba")
               &rArr; ans =
                  {
                    [1,1] =
          
                       1   3   5
          
                    [1,2] = [](1x0)
                    [1,3] = [](1x0)
                  }
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dfindstr.html#doc_002dfindstr">findstr</a>, <a href="doc_002dstrmatch.html#doc_002dstrmatch">strmatch</a>, <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>, <a href="doc_002dregexpi.html#doc_002dregexpi">regexpi</a>, <a href="doc_002dfind.html#doc_002dfind">find</a>. 
</p></blockquote></div>

<!-- strmatch scripts/strings/strmatch.m -->
   <p><a name="doc_002dstrmatch"></a>

<div class="defun">
&mdash; Function File:  <b>strmatch</b> (<var>s, A</var>)<var><a name="index-strmatch-371"></a></var><br>
&mdash; Function File:  <b>strmatch</b> (<var>s, A, "exact"</var>)<var><a name="index-strmatch-372"></a></var><br>
<blockquote><p>Return indices of entries of <var>A</var> which begin with the string <var>s</var>. 
The second argument <var>A</var> must be a string, character matrix, or a cell
array of strings.  If the third argument <code>"exact"</code> is not given, then
<var>s</var> only needs to match <var>A</var> up to the length of <var>s</var>. 
Trailing spaces and nulls in <var>s</var> and <var>A</var> are ignored when matching. 
option.

        <p>For example:

     <pre class="example">          strmatch ("apple", "apple juice")
               &rArr; 1
          
          strmatch ("apple", ["apple  "; "apple juice"; "an apple"])
               &rArr; [1; 2]
          
          strmatch ("apple", ["apple  "; "apple juice"; "an apple"], "exact")
               &rArr; [1]
</pre>
        <p><strong>Caution:</strong> <code>strmatch</code> is scheduled for deprecation.  Use
<code>strcmpi</code> or <code>strncmpi</code> in all new code. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrfind.html#doc_002dstrfind">strfind</a>, <a href="doc_002dfindstr.html#doc_002dfindstr">findstr</a>, <a href="doc_002dstrcmp.html#doc_002dstrcmp">strcmp</a>, <a href="doc_002dstrncmp.html#doc_002dstrncmp">strncmp</a>, <a href="doc_002dstrcmpi.html#doc_002dstrcmpi">strcmpi</a>, <a href="doc_002dstrncmpi.html#doc_002dstrncmpi">strncmpi</a>, <a href="doc_002dfind.html#doc_002dfind">find</a>. 
</p></blockquote></div>

<!-- strtok scripts/strings/strtok.m -->
   <p><a name="doc_002dstrtok"></a>

<div class="defun">
&mdash; Function File: [<var>tok</var>, <var>rem</var>] = <b>strtok</b> (<var>str</var>)<var><a name="index-strtok-373"></a></var><br>
&mdash; Function File: [<var>tok</var>, <var>rem</var>] = <b>strtok</b> (<var>str, delim</var>)<var><a name="index-strtok-374"></a></var><br>
<blockquote>
        <p>Find all characters in the string <var>str</var> up to, but not including, the
first character which is in the string <var>delim</var>.  If <var>rem</var> is
requested, it contains the remainder of the string, starting at the first
delimiter.  Leading delimiters are ignored.  If <var>delim</var> is not
specified, whitespace is assumed.  <var>str</var> may also be a cell array of
strings in which case the function executes on every individual string
and returns a cell array of tokens and remainders.

        <p>Examples:

     <pre class="example">          strtok ("this is the life")
               &rArr; "this"
          
          [tok, rem] = strtok ("14*27+31", "+-*/")
               &rArr;
                  tok = 14
                  rem = *27+31
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dindex.html#doc_002dindex">index</a>, <a href="doc_002dstrsplit.html#doc_002dstrsplit">strsplit</a>, <a href="doc_002dstrchr.html#doc_002dstrchr">strchr</a>, <a href="doc_002disspace.html#doc_002disspace">isspace</a>. 
</p></blockquote></div>

<!-- strsplit scripts/strings/strsplit.m -->
   <p><a name="doc_002dstrsplit"></a>

<div class="defun">
&mdash; Function File: [<var>cstr</var>] = <b>strsplit</b> (<var>s, sep</var>)<var><a name="index-strsplit-375"></a></var><br>
&mdash; Function File: [<var>cstr</var>] = <b>strsplit</b> (<var>s, sep, strip_empty</var>)<var><a name="index-strsplit-376"></a></var><br>
<blockquote><p>Split the string <var>s</var> using one or more separators <var>sep</var> and return
a cell array of strings.  Consecutive separators and separators at
boundaries result in empty strings, unless <var>strip_empty</var> is true. 
The default value of <var>strip_empty</var> is false.

        <p>2-D character arrays are split at separators and at the original column
boundaries.

        <p>Example:

     <pre class="example">          strsplit ("a,b,c", ",")
                &rArr;
                    {
                      [1,1] = a
                      [1,2] = b
                      [1,3] = c
                    }
          
          strsplit (["a,b" ; "cde"], ",")
                &rArr;
                    {
                      [1,1] = a
                      [1,2] = b
                      [1,3] = cde
                    }
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrtok.html#doc_002dstrtok">strtok</a>. 
</p></blockquote></div>

<!-- strread scripts/io/strread.m -->
   <p><a name="doc_002dstrread"></a>

<div class="defun">
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>strread</b> (<var>str</var>)<var><a name="index-strread-377"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>strread</b> (<var>str, format</var>)<var><a name="index-strread-378"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>strread</b> (<var>str, format, format_repeat</var>)<var><a name="index-strread-379"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>strread</b> (<var>str, format, prop1, value1, <small class="dots">...</small></var>)<var><a name="index-strread-380"></a></var><br>
&mdash; Function File: [<var>a</var>, <small class="dots">...</small>] = <b>strread</b> (<var>str, format, format_repeat, prop1, value1, <small class="dots">...</small></var>)<var><a name="index-strread-381"></a></var><br>
<blockquote><p>Read data from a string.

        <p>The string <var>str</var> is split into words that are repeatedly matched to the
specifiers in <var>format</var>.  The first word is matched to the first
specifier, the second to the second specifier and so forth.  If there are
more words than specifiers, the process is repeated until all words have
been processed.

        <p>The string <var>format</var> describes how the words in <var>str</var> should be
parsed. 
It may contain any combination of the following specifiers:

          <dl>
<dt><code>%s</code><dd>The word is parsed as a string.

          <dt><code>%f</code><dt><code>%n</code><dd>The word is parsed as a number and converted to double.

          <br><dt><code>%d</code><dt><code>%u</code><dd>The word is parsed as a number and converted to int32.

          <br><dt><code>%*', '%*f', '%*s</code><dd>The word is skipped.

          <p>For %s and %d, %f, %n, %u and the associated %*s <small class="dots">...</small> specifiers an
optional width can be specified as %Ns, etc. where N is an integer &gt; 1. 
For %f, format specifiers like %N.Mf are allowed.

          <br><dt><code>literals</code><dd>In addition the format may contain literal character strings; these will be
skipped during reading. 
</dl>

        <p>Parsed word corresponding to the first specifier are returned in the first
output argument and likewise for the rest of the specifiers.

        <p>By default, <var>format</var> is <tt>"%f"</tt>, meaning that numbers are read from
<var>str</var>.  This will do if <var>str</var> contains only numeric fields.

        <p>For example, the string

     <pre class="example">          <var>str</var> = "\
          Bunny Bugs   5.5\n\
          Duck Daffy  -7.5e-5\n\
          Penguin Tux   6"
</pre>
        <p class="noindent">can be read using

     <pre class="example">          [<var>a</var>, <var>b</var>, <var>c</var>] = strread (<var>str</var>, "%s %s %f");
</pre>
        <p>Optional numeric argument <var>format_repeat</var> can be used for
limiting the number of items read:

          <dl>
<dt>-1<dd>(default) read all of the string until the end.

          <br><dt>N<dd>Read N times <var>nargout</var> items.  0 (zero) is an acceptable
value for <var>format_repeat</var>. 
</dl>

        <p>The behavior of <code>strread</code> can be changed via property-value
pairs.  The following properties are recognized:

          <dl>
<dt>"commentstyle"<dd>Parts of <var>str</var> are considered comments and will be skipped. 
<var>value</var> is the comment style and can be any of the following.
               <ul>
<li>"shell"
Everything from <code>#</code> characters to the nearest end-of-line is skipped.

               <li>"c"
Everything between <code>/*</code> and <code>*/</code> is skipped.

               <li>"c++"
Everything from <code>//</code> characters to the nearest end-of-line is skipped.

               <li>"matlab"
Everything from <code>%</code> characters to the nearest end-of-line is skipped.

               <li>user-supplied.  Two options:
(1) One string, or 1x1 cell string: Skip everything to the right of it;
(2) 2x1 cell string array: Everything between the left and right strings
is skipped. 
</ul>

          <br><dt>"delimiter"<dd>Any character in <var>value</var> will be used to split <var>str</var> into words
(default value = any whitespace).

          <br><dt>"emptyvalue":<dd>Value to return for empty numeric values in non-whitespace delimited data. 
The default is NaN.  When the data type does not support NaN
(int32 for example), then default is zero.

          <br><dt>"multipledelimsasone"<dd>Treat a series of consecutive delimiters, without whitespace in between,
as a single delimiter.  Consecutive delimiter series need not be vertically
"aligned".

          <br><dt>"treatasempty"<dd>Treat single occurrences (surrounded by delimiters or whitespace) of the
string(s) in <var>value</var> as missing values.

          <br><dt>"returnonerror"<dd>If <var>value</var> true (1, default), ignore read errors and return normally. 
If false (0), return an error.

          <br><dt>"whitespace"<dd>Any character in <var>value</var> will be interpreted as whitespace and
trimmed; the string defining whitespace must be enclosed in double
quotes for proper processing of special characters like \t. 
The default value for whitespace = " \b\r\n\t" (note the space). 
Unless whitespace is set to &rdquo; (empty) AND at least one "%s" format
conversion specifier is supplied, a space is always part of whitespace.

        </dl>

     <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dtextscan.html#doc_002dtextscan">textscan</a>, <a href="doc_002dtextread.html#doc_002dtextread">textread</a>, <a href="doc_002dload.html#doc_002dload">load</a>, <a href="doc_002ddlmread.html#doc_002ddlmread">dlmread</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>. 
</p></blockquote></div>

<!-- strrep src/DLD-FUNCTIONS/strfind.cc -->
   <p><a name="doc_002dstrrep"></a>

<div class="defun">
&mdash; Loadable Function:  <b>strrep</b> (<var>s, ptn, rep</var>)<var><a name="index-strrep-382"></a></var><br>
&mdash; Loadable Function:  <b>strrep</b> (<var>s, ptn, rep, "overlaps", o</var>)<var><a name="index-strrep-383"></a></var><br>
<blockquote><p>Replace all occurrences of the substring <var>ptn</var> in the string <var>s</var>
with the string <var>rep</var> and return the result.  For example:

     <pre class="example">          strrep ("This is a test string", "is", "&amp;%$")
               &rArr; "Th&amp;%$ &amp;%$ a test string"
</pre>
        <p><var>s</var> may also be a cell array of strings, in which case the replacement is
done for each element and a cell array is returned. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dregexprep.html#doc_002dregexprep">regexprep</a>, <a href="doc_002dstrfind.html#doc_002dstrfind">strfind</a>, <a href="doc_002dfindstr.html#doc_002dfindstr">findstr</a>. 
</p></blockquote></div>

<!-- substr scripts/strings/substr.m -->
   <p><a name="doc_002dsubstr"></a>

<div class="defun">
&mdash; Function File:  <b>substr</b> (<var>s, offset</var>)<var><a name="index-substr-384"></a></var><br>
&mdash; Function File:  <b>substr</b> (<var>s, offset, len</var>)<var><a name="index-substr-385"></a></var><br>
<blockquote><p>Return the substring of <var>s</var> which starts at character number
<var>offset</var> and is <var>len</var> characters long.

        <p>Position numbering for offsets begins with 1.  If <var>offset</var> is negative,
extraction starts that far from the end of the string.

        <p>If <var>len</var> is omitted, the substring extends to the end of <var>S</var>.  A
negative value for <var>len</var> extracts to within <var>len</var> characters of
the end of the string

        <p>Examples:

     <pre class="example">          substr ("This is a test string", 6, 9)
               &rArr; "is a test"
          substr ("This is a test string", -11)
               &rArr; "test string"
          substr ("This is a test string", -11, -7)
               &rArr; "test"
</pre>
        <p>This function is patterned after the equivalent function in Perl. 
</p></blockquote></div>

<!-- regexp src/DLD-FUNCTIONS/regexp.cc -->
   <p><a name="doc_002dregexp"></a>

<div class="defun">
&mdash; Loadable Function: [<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>] = <b>regexp</b> (<var>str, pat</var>)<var><a name="index-regexp-386"></a></var><br>
&mdash; Loadable Function: [<small class="dots">...</small>] = <b>regexp</b> (<var>str, pat, "opt1", <small class="dots">...</small></var>)<var><a name="index-regexp-387"></a></var><br>
<blockquote><p>Regular expression string matching.  Search for <var>pat</var> in <var>str</var> and
return the positions and substrings of any matches, or empty values if there
are none.

        <p>The matched pattern <var>pat</var> can include any of the standard regex
operators, including:

          <dl>
<dt><code>.</code><dd>Match any character

          <br><dt><code>* + ? {}</code><dd>Repetition operators, representing
               <dl>
<dt><code>*</code><dd>Match zero or more times

               <br><dt><code>+</code><dd>Match one or more times

               <br><dt><code>?</code><dd>Match zero or one times

               <br><dt><code>{</code><var>n</var><code>}</code><dd>Match exactly <var>n</var> times

               <br><dt><code>{</code><var>n</var><code>,}</code><dd>Match <var>n</var> or more times

               <br><dt><code>{</code><var>m</var><code>,</code><var>n</var><code>}</code><dd>Match between <var>m</var> and <var>n</var> times
</dl>

          <br><dt><code>[...] [^...]</code><dd>
List operators.  The pattern will match any character listed between "["
and "]".  If the first character is "^" then the pattern is inverted and
any character except those listed between brackets will match.

          <p>Escape sequences defined below can also be used inside list
operators.  For example, a template for a floating point number might be
<code>[-+.\d]+</code>.

          <br><dt><code>()</code><dd>Grouping operator

          <br><dt><code>|</code><dd>Alternation operator.  Match one of a choice of regular expressions.  The
alternatives must be delimited by the grouping operator <code>()</code> above.

          <br><dt><code>^ $</code><dd>Anchoring operators.  Requires pattern to occur at the start (<code>^</code>) or
end (<code>$</code>) of the string. 
</dl>

        <p>In addition, the following escaped characters have special meaning.  Note,
it is recommended to quote <var>pat</var> in single quotes, rather than double
quotes, to avoid the escape sequences being interpreted by Octave before
being passed to <code>regexp</code>.

          <dl>
<dt><code>\b</code><dd>Match a word boundary

          <br><dt><code>\B</code><dd>Match within a word

          <br><dt><code>\w</code><dd>Match any word character

          <br><dt><code>\W</code><dd>Match any non-word character

          <br><dt><code>\&lt;</code><dd>Match the beginning of a word

          <br><dt><code>\&gt;</code><dd>Match the end of a word

          <br><dt><code>\s</code><dd>Match any whitespace character

          <br><dt><code>\S</code><dd>Match any non-whitespace character

          <br><dt><code>\d</code><dd>Match any digit

          <br><dt><code>\D</code><dd>Match any non-digit
</dl>

        <p>The outputs of <code>regexp</code> default to the order given below

          <dl>
<dt><var>s</var><dd>The start indices of each matching substring

          <br><dt><var>e</var><dd>The end indices of each matching substring

          <br><dt><var>te</var><dd>The extents of each matched token surrounded by <code>(...)</code> in
<var>pat</var>

          <br><dt><var>m</var><dd>A cell array of the text of each match

          <br><dt><var>t</var><dd>A cell array of the text of each token matched

          <br><dt><var>nm</var><dd>A structure containing the text of each matched named token, with the name
being used as the fieldname.  A named token is denoted by
<code>(?&lt;name&gt;...)</code>.

          <br><dt><var>sp</var><dd>A cell array of the text not returned by match. 
</dl>

        <p>Particular output arguments, or the order of the output arguments, can be
selected by additional <var>opt</var> arguments.  These are strings and the
correspondence between the output arguments and the optional argument
are

        <p><table summary=""><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'start'        </td><td valign="top" width="30%"><var>s</var>  </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'end'          </td><td valign="top" width="30%"><var>e</var>  </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'tokenExtents' </td><td valign="top" width="30%"><var>te</var> </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'match'        </td><td valign="top" width="30%"><var>m</var>  </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'tokens'       </td><td valign="top" width="30%"><var>t</var>  </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'names'        </td><td valign="top" width="30%"><var>nm</var> </td><td valign="top" width="20%">
<br></td></tr><tr align="left"><td valign="top" width="20%"></td><td valign="top" width="30%">'split'        </td><td valign="top" width="30%"><var>sp</var> </td><td valign="top" width="20%">
        <br></td></tr></table>

        <p>Additional arguments are summarized below.

          <dl>
<dt>&lsquo;<samp><span class="samp">once</span></samp>&rsquo;<dd>Return only the first occurrence of the pattern.

          <br><dt>&lsquo;<samp><span class="samp">matchcase</span></samp>&rsquo;<dd>Make the matching case sensitive.  (default)

          <p>Alternatively, use (?-i) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">ignorecase</span></samp>&rsquo;<dd>Ignore case when matching the pattern to the string.

          <p>Alternatively, use (?i) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">stringanchors</span></samp>&rsquo;<dd>Match the anchor characters at the beginning and end of the string. 
(default)

          <p>Alternatively, use (?-m) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">lineanchors</span></samp>&rsquo;<dd>Match the anchor characters at the beginning and end of the line.

          <p>Alternatively, use (?m) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">dotall</span></samp>&rsquo;<dd>The pattern <code>.</code> matches all characters including the newline character. 
 (default)

          <p>Alternatively, use (?s) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">dotexceptnewline</span></samp>&rsquo;<dd>The pattern <code>.</code> matches all characters except the newline character.

          <p>Alternatively, use (?-s) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">literalspacing</span></samp>&rsquo;<dd>All characters in the pattern, including whitespace, are significant and are
used in pattern matching.  (default)

          <p>Alternatively, use (?-x) in the pattern.

          <br><dt>&lsquo;<samp><span class="samp">freespacing</span></samp>&rsquo;<dd>The pattern may include arbitrary whitespace and also comments beginning with
the character &lsquo;<samp><span class="samp">#</span></samp>&rsquo;.

          <p>Alternatively, use (?x) in the pattern.

        </dl>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dregexpi.html#doc_002dregexpi">regexpi</a>, <a href="doc_002dstrfind.html#doc_002dstrfind">strfind</a>, <a href="doc_002dregexprep.html#doc_002dregexprep">regexprep</a>. 
</p></blockquote></div>

<!-- regexpi src/DLD-FUNCTIONS/regexp.cc -->
   <p><a name="doc_002dregexpi"></a>

<div class="defun">
&mdash; Loadable Function: [<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>] = <b>regexpi</b> (<var>str, pat</var>)<var><a name="index-regexpi-388"></a></var><br>
&mdash; Loadable Function: [<small class="dots">...</small>] = <b>regexpi</b> (<var>str, pat, "opt1", <small class="dots">...</small></var>)<var><a name="index-regexpi-389"></a></var><br>
<blockquote>
        <p>Case insensitive regular expression string matching.  Search for <var>pat</var> in
<var>str</var> and return the positions and substrings of any matches, or empty
values if there are none.  See <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>, for details on the
syntax of the search pattern. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>. 
</p></blockquote></div>

<!-- regexprep src/DLD-FUNCTIONS/regexp.cc -->
   <p><a name="doc_002dregexprep"></a>

<div class="defun">
&mdash; Loadable Function: <var>outstr</var> = <b>regexprep</b> (<var>string, pat, repstr</var>)<var><a name="index-regexprep-390"></a></var><br>
&mdash; Loadable Function: <var>outstr</var> = <b>regexprep</b> (<var>string, pat, repstr, "opt1", <small class="dots">...</small></var>)<var><a name="index-regexprep-391"></a></var><br>
<blockquote><p>Replace occurrences of pattern <var>pat</var> in <var>string</var> with <var>repstr</var>.

        <p>The pattern is a regular expression as documented for <code>regexp</code>. 
See <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>.

        <p>The replacement string may contain <code>$i</code>, which substitutes
for the ith set of parentheses in the match string.  For example,

     <pre class="example">          regexprep("Bill Dunn",'(\w+) (\w+)','$2, $1')
</pre>
        <p class="noindent">returns "Dunn, Bill"

        <p>Options in addition to those of <code>regexp</code> are

          <dl>
<dt>&lsquo;<samp><span class="samp">once</span></samp>&rsquo;<dd>Replace only the first occurrence of <var>pat</var> in the result.

          <br><dt>&lsquo;<samp><span class="samp">warnings</span></samp>&rsquo;<dd>This option is present for compatibility but is ignored.

        </dl>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>, <a href="doc_002dregexpi.html#doc_002dregexpi">regexpi</a>, <a href="doc_002dstrrep.html#doc_002dstrrep">strrep</a>. 
</p></blockquote></div>

<!-- regexptranslate scripts/strings/regexptranslate.m -->
   <p><a name="doc_002dregexptranslate"></a>

<div class="defun">
&mdash; Function File:  <b>regexptranslate</b> (<var>op, s</var>)<var><a name="index-regexptranslate-392"></a></var><br>
<blockquote><p>Translate a string for use in a regular expression.  This may
include either wildcard replacement or special character escaping. 
The behavior is controlled by <var>op</var> which can take the following
values

          <dl>
<dt>"wildcard"<dd>The wildcard characters <code>.</code>, <code>*</code>, and <code>?</code> are replaced
with wildcards that are appropriate for a regular expression. 
For example:

          <pre class="example">               regexptranslate ("wildcard", "*.m")
                    &rArr; ".*\.m"
</pre>
          <br><dt>"escape"<dd>The characters <code>$.?[]</code>, that have special meaning for regular
expressions are escaped so that they are treated literally.  For example:

          <pre class="example">               regexptranslate ("escape", "12.5")
                    &rArr; "12\.5"
</pre>
          </dl>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dregexp.html#doc_002dregexp">regexp</a>, <a href="doc_002dregexpi.html#doc_002dregexpi">regexpi</a>, <a href="doc_002dregexprep.html#doc_002dregexprep">regexprep</a>. 
</p></blockquote></div>

<!-- untabify scripts/strings/untabify.m -->
   <p><a name="doc_002duntabify"></a>

<div class="defun">
&mdash; Function File:  <b>untabify</b> (<var>t</var>)<var><a name="index-untabify-393"></a></var><br>
&mdash; Function File:  <b>untabify</b> (<var>t, tw</var>)<var><a name="index-untabify-394"></a></var><br>
&mdash; Function File:  <b>untabify</b> (<var>t, tw, deblank</var>)<var><a name="index-untabify-395"></a></var><br>
<blockquote><p>Replace TAB characters in <var>t</var>, with spaces. 
The tab width is specified by <var>tw</var>, or defaults to eight. 
The input, <var>t</var>, may be either a 2-D character array, or a cell
array of character strings.  The output is the same class
as the input.

        <p>If the optional argument <var>deblank</var> is true, then the spaces will
be removed from the end of the character data.

        <p>The following example reads a file and writes an untabified version
of the same file with trailing spaces stripped.

     <pre class="example">          fid = fopen ("tabbed_script.m");
          text = char (fread (fid, "uchar")');
          fclose (fid);
          fid = fopen ("untabified_script.m", "w");
          text = untabify (strsplit (text, "\n"), 8, true);
          fprintf (fid, "%s\n", text{:});
          fclose (fid);
</pre>
        <!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
     <!-- A simple blank line produces the correct behavior. -->
     <!-- @sp 1 -->
     <p class="noindent"><strong>See also:</strong> <a href="doc_002dstrjust.html#doc_002dstrjust">strjust</a>, <a href="doc_002dstrsplit.html#doc_002dstrsplit">strsplit</a>, <a href="doc_002ddeblank.html#doc_002ddeblank">deblank</a>. 
</p></blockquote></div>

   </body></html>