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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.8, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Searching in Strings (GNU Octave (version 7.3.0))</title>
<meta name="description" content="Searching in Strings (GNU Octave (version 7.3.0))">
<meta name="keywords" content="Searching in Strings (GNU Octave (version 7.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="String-Operations.html" rel="up" title="String Operations">
<link href="Searching-and-Replacing-in-Strings.html" rel="next" title="Searching and Replacing in Strings">
<link href="Splitting-and-Joining-Strings.html" rel="prev" title="Splitting and Joining Strings">
<style type="text/css">
<!--
a.copiable-anchor {visibility: hidden; text-decoration: none; line-height: 0em}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
span:hover a.copiable-anchor {visibility: visible}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="subsection" id="Searching-in-Strings">
<div class="header">
<p>
Next: <a href="Searching-and-Replacing-in-Strings.html" accesskey="n" rel="next">Searching and Replacing in Strings</a>, Previous: <a href="Splitting-and-Joining-Strings.html" accesskey="p" rel="prev">Splitting and Joining Strings</a>, Up: <a href="String-Operations.html" accesskey="u" rel="up">String Operations</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="Searching-in-Strings-1"></span><h4 class="subsection">5.3.4 Searching in Strings</h4>
<p>Since a string is a character array, comparisons between strings work
element by element as the following example shows:
</p>
<div class="example">
<pre class="example">GNU = "GNU's Not UNIX";
spaces = (GNU == " ")
⇒ spaces =
0 0 0 0 0 1 0 0 0 1 0 0 0 0
</pre></div>
<p>To determine if two strings are identical it is necessary to use the
<code>strcmp</code> function. It compares complete strings and is case
sensitive. <code>strncmp</code> compares only the first <code>N</code> characters (with
<code>N</code> given as a parameter). <code>strcmpi</code> and <code>strncmpi</code> are the
corresponding functions for case-insensitive comparison.
</p>
<span id="XREFstrcmp"></span><dl class="def">
<dt id="index-strcmp"><span class="category">: </span><span><em></em> <strong>strcmp</strong> <em>(<var>s1</var>, <var>s2</var>)</em><a href='#index-strcmp' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return 1 if the character strings <var>s1</var> and <var>s2</var> are the same,
and 0 otherwise.
</p>
<p>If either <var>s1</var> or <var>s2</var> is a cell array of strings, then an array
of the same size is returned, containing the values described above for
every member of the cell array. The other argument may also be a cell
array of strings (of the same size or with only one element), char matrix
or character string.
</p>
<p><strong>Caution:</strong> For compatibility with <small>MATLAB</small>, Octave’s strcmp
function returns 1 if the character strings are equal, and 0 otherwise.
This is just the opposite of the corresponding C library function.
</p>
<p><strong>See also:</strong> <a href="#XREFstrcmpi">strcmpi</a>, <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrncmpi">strncmpi</a>.
</p></dd></dl>
<span id="XREFstrncmp"></span><dl class="def">
<dt id="index-strncmp"><span class="category">: </span><span><em></em> <strong>strncmp</strong> <em>(<var>s1</var>, <var>s2</var>, <var>n</var>)</em><a href='#index-strncmp' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return 1 if the first <var>n</var> characters of strings <var>s1</var> and <var>s2</var>
are the same, and 0 otherwise.
</p>
<div class="example">
<pre class="example">strncmp ("abce", "abcd", 3)
⇒ 1
</pre></div>
<p>If either <var>s1</var> or <var>s2</var> is a cell array of strings, then an array
of the same size is returned, containing the values described above for
every member of the cell array. The other argument may also be a cell
array of strings (of the same size or with only one element), char matrix
or character string.
</p>
<div class="example">
<pre class="example">strncmp ("abce", {"abcd", "bca", "abc"}, 3)
⇒ [1, 0, 1]
</pre></div>
<p><strong>Caution:</strong> For compatibility with <small>MATLAB</small>, Octave’s strncmp
function returns 1 if the character strings are equal, and 0 otherwise.
This is just the opposite of the corresponding C library function.
</p>
<p><strong>See also:</strong> <a href="#XREFstrncmpi">strncmpi</a>, <a href="#XREFstrcmp">strcmp</a>, <a href="#XREFstrcmpi">strcmpi</a>.
</p></dd></dl>
<span id="XREFstrcmpi"></span><dl class="def">
<dt id="index-strcmpi"><span class="category">: </span><span><em></em> <strong>strcmpi</strong> <em>(<var>s1</var>, <var>s2</var>)</em><a href='#index-strcmpi' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return 1 if the character strings <var>s1</var> and <var>s2</var> are the same,
disregarding case of alphabetic characters, and 0 otherwise.
</p>
<p>If either <var>s1</var> or <var>s2</var> is a cell array of strings, then an array
of the same size is returned, containing the values described above for
every member of the cell array. The other argument may also be a cell
array of strings (of the same size or with only one element), char matrix
or character string.
</p>
<p><strong>Caution:</strong> For compatibility with <small>MATLAB</small>, Octave’s strcmp
function returns 1 if the character strings are equal, and 0 otherwise.
This is just the opposite of the corresponding C library function.
</p>
<p><strong>Caution:</strong> National alphabets are not supported.
</p>
<p><strong>See also:</strong> <a href="#XREFstrcmp">strcmp</a>, <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrncmpi">strncmpi</a>.
</p></dd></dl>
<span id="XREFstrncmpi"></span><dl class="def">
<dt id="index-strncmpi"><span class="category">: </span><span><em></em> <strong>strncmpi</strong> <em>(<var>s1</var>, <var>s2</var>, <var>n</var>)</em><a href='#index-strncmpi' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return 1 if the first <var>n</var> character of <var>s1</var> and <var>s2</var> are the
same, disregarding case of alphabetic characters, and 0 otherwise.
</p>
<p>If either <var>s1</var> or <var>s2</var> is a cell array of strings, then an array
of the same size is returned, containing the values described above for
every member of the cell array. The other argument may also be a cell
array of strings (of the same size or with only one element), char matrix
or character string.
</p>
<p><strong>Caution:</strong> For compatibility with <small>MATLAB</small>, Octave’s strncmpi
function returns 1 if the character strings are equal, and 0 otherwise.
This is just the opposite of the corresponding C library function.
</p>
<p><strong>Caution:</strong> National alphabets are not supported.
</p>
<p><strong>See also:</strong> <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrcmp">strcmp</a>, <a href="#XREFstrcmpi">strcmpi</a>.
</p></dd></dl>
<p>Despite those comparison functions, there are more specialized function to
find the index position of a search pattern within a string.
</p>
<span id="XREFstartsWith"></span><dl class="def">
<dt id="index-startsWith"><span class="category">: </span><span><em><var>retval</var> =</em> <strong>startsWith</strong> <em>(<var>str</var>, <var>pattern</var>)</em><a href='#index-startsWith' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-startsWith-1"><span class="category">: </span><span><em><var>retval</var> =</em> <strong>startsWith</strong> <em>(<var>str</var>, <var>pattern</var>, "IgnoreCase", <var>ignore_case</var>)</em><a href='#index-startsWith-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Check whether string(s) start with pattern(s).
</p>
<p>Return an array of logical values that indicates which string(s) in the
input <var>str</var> (a single string or cell array of strings) begin with
the input <var>pattern</var> (a single string or cell array of strings).
</p>
<p>If the value of the parameter <code>"IgnoreCase"</code> is true, then the
function will ignore the letter case of <var>str</var> and <var>pattern</var>. By
default, the comparison is case sensitive.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">## one string and one pattern while considering case
startsWith ("hello", "he")
⇒ 1
</pre><pre class="example">
</pre><pre class="example">## one string and one pattern while ignoring case
startsWith ("hello", "HE", "IgnoreCase", true)
⇒ 1
</pre><pre class="example">
</pre><pre class="example">## multiple strings and multiple patterns while considering case
startsWith ({"lab work.pptx", "data.txt", "foundations.ppt"},
{"lab", "data"})
⇒ 1 1 0
</pre><pre class="example">
</pre><pre class="example">## multiple strings and one pattern while considering case
startsWith ({"DATASHEET.ods", "data.txt", "foundations.ppt"},
"data", "IgnoreCase", false)
⇒ 0 1 0
</pre><pre class="example">
</pre><pre class="example">## multiple strings and one pattern while ignoring case
startsWith ({"DATASHEET.ods", "data.txt", "foundations.ppt"},
"data", "IgnoreCase", true)
⇒ 1 1 0
</pre></div>
<p><strong>See also:</strong> <a href="#XREFendsWith">endsWith</a>, <a href="Searching-and-Replacing-in-Strings.html#XREFregexp">regexp</a>, <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrncmpi">strncmpi</a>.
</p></dd></dl>
<span id="XREFendsWith"></span><dl class="def">
<dt id="index-endsWith"><span class="category">: </span><span><em><var>retval</var> =</em> <strong>endsWith</strong> <em>(<var>str</var>, <var>pattern</var>)</em><a href='#index-endsWith' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-endsWith-1"><span class="category">: </span><span><em><var>retval</var> =</em> <strong>endsWith</strong> <em>(<var>str</var>, <var>pattern</var>, "IgnoreCase", <var>ignore_case</var>)</em><a href='#index-endsWith-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Check whether string(s) end with pattern(s).
</p>
<p>Return an array of logical values that indicates which string(s) in the
input <var>str</var> (a single string or cell array of strings) end with
the input <var>pattern</var> (a single string or cell array of strings).
</p>
<p>If the value of the parameter <code>"IgnoreCase"</code> is true, then the
function will ignore the letter case of <var>str</var> and <var>pattern</var>. By
default, the comparison is case sensitive.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">## one string and one pattern while considering case
endsWith ("hello", "lo")
⇒ 1
</pre><pre class="example">
</pre><pre class="example">## one string and one pattern while ignoring case
endsWith ("hello", "LO", "IgnoreCase", true)
⇒ 1
</pre><pre class="example">
</pre><pre class="example">## multiple strings and multiple patterns while considering case
endsWith ({"tests.txt", "mydoc.odt", "myFunc.m", "results.pptx"},
{".docx", ".odt", ".txt"})
⇒ 1 1 0 0
</pre><pre class="example">
</pre><pre class="example">## multiple strings and one pattern while considering case
endsWith ({"TESTS.TXT", "mydoc.odt", "result.txt", "myFunc.m"},
".txt", "IgnoreCase", false)
⇒ 0 0 1 0
</pre><pre class="example">
</pre><pre class="example">## multiple strings and one pattern while ignoring case
endsWith ({"TESTS.TXT", "mydoc.odt", "result.txt", "myFunc.m"},
".txt", "IgnoreCase", true)
⇒ 1 0 1 0
</pre></div>
<p><strong>See also:</strong> <a href="#XREFstartsWith">startsWith</a>, <a href="Searching-and-Replacing-in-Strings.html#XREFregexp">regexp</a>, <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrncmpi">strncmpi</a>.
</p></dd></dl>
<span id="XREFfindstr"></span><dl class="def">
<dt id="index-findstr"><span class="category">: </span><span><em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>)</em><a href='#index-findstr' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-findstr-1"><span class="category">: </span><span><em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>, <var>overlap</var>)</em><a href='#index-findstr-1' class='copiable-anchor'> ¶</a></span></dt>
<dd>
<p>This function is obsolete. Use <code>strfind</code> instead.
</p>
<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.
</p>
<p>If the optional argument <var>overlap</var> is true (default), the returned
vector can include overlapping positions. For example:
</p>
<div class="example">
<pre class="example">findstr ("ababab", "a")
⇒ [1, 3, 5];
findstr ("abababa", "aba", 0)
⇒ [1, 5]
</pre></div>
<p><strong>Caution:</strong> <code>findstr</code> is obsolete. Use <code>strfind</code> in all new
code.
</p>
<p><strong>See also:</strong> <a href="#XREFstrfind">strfind</a>, <a href="#XREFstrmatch">strmatch</a>, <a href="#XREFstrcmp">strcmp</a>, <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrcmpi">strcmpi</a>, <a href="#XREFstrncmpi">strncmpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>
<span id="XREFstrchr"></span><dl class="def">
<dt id="index-strchr"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>)</em><a href='#index-strchr' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strchr-1"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>)</em><a href='#index-strchr-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strchr-2"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>, <var>direction</var>)</em><a href='#index-strchr-2' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strchr-3"><span class="category">: </span><span><em>[<var>i</var>, <var>j</var>] =</em> <strong>strchr</strong> <em>(…)</em><a href='#index-strchr-3' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Search through the string <var>str</var> for occurrences of characters from the
set <var>chars</var>.
</p>
<p>The return value(s), as well as the <var>n</var> and <var>direction</var> arguments
behave identically as in <code>find</code>.
</p>
<p>This will be faster than using <code>regexp</code> in most cases.
</p>
<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>
<span id="XREFindex"></span><dl class="def">
<dt id="index-index"><span class="category">: </span><span><em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>)</em><a href='#index-index' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-index-1"><span class="category">: </span><span><em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>, <var>direction</var>)</em><a href='#index-index-1' class='copiable-anchor'> ¶</a></span></dt>
<dd><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.
</p>
<p><var>s</var> may also be a string array or cell array of strings.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">index ("Teststring", "t")
⇒ 4
</pre></div>
<p>If <var>direction</var> is <code>"first"</code>, return the first element found.
If <var>direction</var> is <code>"last"</code>, return the last element found.
</p>
<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>, <a href="#XREFrindex">rindex</a>.
</p></dd></dl>
<span id="XREFrindex"></span><dl class="def">
<dt id="index-rindex"><span class="category">: </span><span><em></em> <strong>rindex</strong> <em>(<var>s</var>, <var>t</var>)</em><a href='#index-rindex' class='copiable-anchor'> ¶</a></span></dt>
<dd><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.
</p>
<p><var>s</var> may also be a string array or cell array of strings.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">rindex ("Teststring", "t")
⇒ 6
</pre></div>
<p>The <code>rindex</code> function is equivalent to <code>index</code> with
<var>direction</var> set to <code>"last"</code>.
</p>
<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>, <a href="#XREFindex">index</a>.
</p></dd></dl>
<span id="XREFunicode_005fidx"></span><dl class="def">
<dt id="index-unicode_005fidx"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>unicode_idx</strong> <em>(<var>str</var>)</em><a href='#index-unicode_005fidx' class='copiable-anchor'> ¶</a></span></dt>
<dd><p>Return an array with the indices for each UTF-8 encoded character in <var>str</var>.
</p>
<div class="example">
<pre class="example">unicode_idx ("aäbc")
⇒ [1, 2, 2, 3, 4]
</pre></div>
</dd></dl>
<span id="XREFstrfind"></span><dl class="def">
<dt id="index-strfind"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>str</var>, <var>pattern</var>)</em><a href='#index-strfind' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strfind-1"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>cellstr</var>, <var>pattern</var>)</em><a href='#index-strfind-1' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strfind-2"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strfind</strong> <em>(…, "overlaps", <var>val</var>)</em><a href='#index-strfind-2' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strfind-3"><span class="category">: </span><span><em><var>idx</var> =</em> <strong>strfind</strong> <em>(…, "forcecelloutput", <var>val</var>)</em><a href='#index-strfind-3' class='copiable-anchor'> ¶</a></span></dt>
<dd><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>.
</p>
<p>If there is no such occurrence, or if <var>pattern</var> is longer than
<var>str</var>, or if <var>pattern</var> itself is empty, then <var>idx</var> is the empty
array <code>[]</code>.
</p>
<p>The optional argument <code>"overlaps"</code> determines whether the pattern
can match at every position in <var>str</var> (true), or only for unique
occurrences of the complete pattern (false). The default is true.
</p>
<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.
</p>
<p>The optional argument <code>"forcecelloutput"</code> forces <var>idx</var> to be
returned as a cell array of vectors. The default is false.
</p>
<p>Examples:
</p>
<div class="example">
<pre class="example">strfind ("abababa", "aba")
⇒ [1, 3, 5]
</pre><pre class="example">
</pre><pre class="example">strfind ("abababa", "aba", "overlaps", false)
⇒ [1, 5]
</pre><pre class="example">
</pre><pre class="example">strfind ({"abababa", "bebebe", "ab"}, "aba")
⇒
{
[1,1] =
1 3 5
[1,2] = [](1x0)
[1,3] = [](1x0)
}
</pre><pre class="example">
</pre><pre class="example">strfind ("abababa", "aba", "forcecelloutput", true)
⇒
{
[1,1] =
1 3 5
}
</pre></div>
<p><strong>See also:</strong> <a href="Searching-and-Replacing-in-Strings.html#XREFregexp">regexp</a>, <a href="Searching-and-Replacing-in-Strings.html#XREFregexpi">regexpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>
<span id="XREFstrmatch"></span><dl class="def">
<dt id="index-strmatch"><span class="category">: </span><span><em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>)</em><a href='#index-strmatch' class='copiable-anchor'> ¶</a></span></dt>
<dt id="index-strmatch-1"><span class="category">: </span><span><em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>, "exact")</em><a href='#index-strmatch-1' class='copiable-anchor'> ¶</a></span></dt>
<dd>
<p>This function is obsolete. <strong>Use an alternative</strong> such as
<code>strncmp</code> or <code>strcmp</code> instead.
</p>
<p>Return indices of entries of <var>A</var> which begin with the string <var>s</var>.
</p>
<p>The second argument <var>A</var> must be a string, character matrix, or a cell
array of strings.
</p>
<p>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.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">strmatch ("apple", "apple juice")
⇒ 1
strmatch ("apple", ["apple "; "apple juice"; "an apple"])
⇒ [1; 2]
strmatch ("apple", ["apple "; "apple juice"; "an apple"], "exact")
⇒ [1]
</pre></div>
<p><strong>Caution:</strong> <code>strmatch</code> is obsolete (and can produce incorrect
results in <small>MATLAB</small> when used with cell arrays of strings. Use
<code>strncmp</code> (normal case) or <code>strcmp</code> (<code>"exact"</code> case) in all
new code. Other replacement possibilities, depending on application,
include <code>regexp</code> or <code>validatestring</code>.
</p>
<p><strong>See also:</strong> <a href="#XREFstrncmp">strncmp</a>, <a href="#XREFstrcmp">strcmp</a>, <a href="Searching-and-Replacing-in-Strings.html#XREFregexp">regexp</a>, <a href="#XREFstrfind">strfind</a>, <a href="Validating-the-type-of-Arguments.html#XREFvalidatestring">validatestring</a>.
</p></dd></dl>
</div>
<hr>
<div class="header">
<p>
Next: <a href="Searching-and-Replacing-in-Strings.html">Searching and Replacing in Strings</a>, Previous: <a href="Splitting-and-Joining-Strings.html">Splitting and Joining Strings</a>, Up: <a href="String-Operations.html">String Operations</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|