File: Manipulating-Strings.html

package info (click to toggle)
octave 3.8.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,396 kB
  • ctags: 45,547
  • sloc: cpp: 293,356; ansic: 42,041; fortran: 23,669; sh: 13,629; objc: 7,890; yacc: 7,093; lex: 3,442; java: 2,125; makefile: 1,589; perl: 1,009; awk: 974; xml: 34
file content (1073 lines) | stat: -rw-r--r-- 43,813 bytes parent folder | download | duplicates (3)
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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>GNU Octave: Manipulating Strings</title>

<meta name="description" content="GNU Octave: Manipulating Strings">
<meta name="keywords" content="GNU Octave: Manipulating Strings">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Strings.html#Strings" rel="up" title="Strings">
<link href="String-Conversions.html#String-Conversions" rel="next" title="String Conversions">
<link href="Comparing-Strings.html#Comparing-Strings" rel="prev" title="Comparing Strings">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {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}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Manipulating-Strings"></a>
<div class="header">
<p>
Next: <a href="String-Conversions.html#String-Conversions" accesskey="n" rel="next">String Conversions</a>, Previous: <a href="Comparing-Strings.html#Comparing-Strings" accesskey="p" rel="prev">Comparing Strings</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Manipulating-Strings-1"></a>
<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.
</p>
<div class="example">
<pre class="example">quote = ...
  &quot;First things first, but not necessarily in that order&quot;;
quote( quote == &quot; &quot; ) = &quot;_&quot;
&rArr; quote = 
    First_things_first,_but_not_necessarily_in_that_order
</pre></div>

<p>For more complex manipulations, such as searching, replacing, and
general regular expressions, the following functions come with Octave.
</p>
<a name="XREFdeblank"></a><dl>
<dt><a name="index-deblank"></a>Function File: <em></em> <strong>deblank</strong> <em>(<var>s</var>)</em></dt>
<dd><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>
<p>Examples:
</p>
<div class="example">
<pre class="example">deblank (&quot;    abc  &quot;)
     &rArr;  &quot;    abc&quot;

deblank ([&quot; abc   &quot;; &quot;   def   &quot;])
     &rArr;  [&quot; abc  &quot; ; &quot;   def&quot;]
</pre></div>

<p><strong>See also:</strong> <a href="#XREFstrtrim">strtrim</a>.
</p></dd></dl>


<a name="XREFstrtrim"></a><dl>
<dt><a name="index-strtrim"></a>Function File: <em></em> <strong>strtrim</strong> <em>(<var>s</var>)</em></dt>
<dd><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:
</p>
<div class="example">
<pre class="example">strtrim (&quot;    abc  &quot;)
     &rArr;  &quot;abc&quot;

strtrim ([&quot; abc   &quot;; &quot;   def   &quot;])
     &rArr;  [&quot;abc  &quot;  ; &quot;  def&quot;]
</pre></div>

<p><strong>See also:</strong> <a href="#XREFdeblank">deblank</a>.
</p></dd></dl>


<a name="XREFstrtrunc"></a><dl>
<dt><a name="index-strtrunc"></a>Function File: <em></em> <strong>strtrunc</strong> <em>(<var>s</var>, <var>n</var>)</em></dt>
<dd><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></dd></dl>


<a name="XREFfindstr"></a><dl>
<dt><a name="index-findstr"></a>Function File: <em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>)</em></dt>
<dt><a name="index-findstr-1"></a>Function File: <em></em> <strong>findstr</strong> <em>(<var>s</var>, <var>t</var>, <var>overlap</var>)</em></dt>
<dd><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:
</p>
<div class="example">
<pre class="example">findstr (&quot;ababab&quot;, &quot;a&quot;)
     &rArr; [1, 3, 5];
findstr (&quot;abababa&quot;, &quot;aba&quot;, 0)
     &rArr; [1, 5]
</pre></div>

<p><strong>Caution:</strong> <code>findstr</code> is scheduled for deprecation.  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="Comparing-Strings.html#XREFstrcmp">strcmp</a>, <a href="Comparing-Strings.html#XREFstrncmp">strncmp</a>, <a href="Comparing-Strings.html#XREFstrcmpi">strcmpi</a>, <a href="Comparing-Strings.html#XREFstrncmpi">strncmpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<a name="XREFstrchr"></a><dl>
<dt><a name="index-strchr"></a>Function File: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>)</em></dt>
<dt><a name="index-strchr-1"></a>Function File: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>)</em></dt>
<dt><a name="index-strchr-2"></a>Function File: <em><var>idx</var> =</em> <strong>strchr</strong> <em>(<var>str</var>, <var>chars</var>, <var>n</var>, <var>direction</var>)</em></dt>
<dt><a name="index-strchr-3"></a>Function File: <em>[<var>i</var>, <var>j</var>] =</em> <strong>strchr</strong> <em>(&hellip;)</em></dt>
<dd><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>
<p>This will be faster than using regexp in most cases.
</p>

<p><strong>See also:</strong> <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<a name="XREFindex"></a><dl>
<dt><a name="index-index"></a>Function File: <em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>)</em></dt>
<dt><a name="index-index-1"></a>Function File: <em></em> <strong>index</strong> <em>(<var>s</var>, <var>t</var>, <var>direction</var>)</em></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.  <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 (&quot;Teststring&quot;, &quot;t&quot;)
    &rArr; 4
</pre></div>

<p>If <var>direction</var> is <code>&quot;first&quot;</code>, return the first element found.
If <var>direction</var> is <code>&quot;last&quot;</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>


<a name="XREFrindex"></a><dl>
<dt><a name="index-rindex"></a>Function File: <em></em> <strong>rindex</strong> <em>(<var>s</var>, <var>t</var>)</em></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.  <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 (&quot;Teststring&quot;, &quot;t&quot;)
     &rArr; 6
</pre></div>

<p>The <code>rindex</code> function is equivalent to <code>index</code> with
<var>direction</var> set to <code>&quot;last&quot;</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>


<a name="XREFstrfind"></a><dl>
<dt><a name="index-strfind"></a>Built-in Function: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>str</var>, <var>pattern</var>)</em></dt>
<dt><a name="index-strfind-1"></a>Built-in Function: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(<var>cellstr</var>, <var>pattern</var>)</em></dt>
<dt><a name="index-strfind-2"></a>Built-in Function: <em><var>idx</var> =</em> <strong>strfind</strong> <em>(&hellip;, &quot;overlaps&quot;, <var>val</var>)</em></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>, then <var>idx</var> is the empty array <code>[]</code>.
The optional argument <code>&quot;overlaps&quot;</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>Examples:
</p>
<div class="example">
<pre class="example">strfind (&quot;abababa&quot;, &quot;aba&quot;)
     &rArr; [1, 3, 5]

strfind (&quot;abababa&quot;, &quot;aba&quot;, &quot;overlaps&quot;, false)
     &rArr; [1, 5]

strfind ({&quot;abababa&quot;, &quot;bebebe&quot;, &quot;ab&quot;}, &quot;aba&quot;)
     &rArr;
        {
          [1,1] =

             1   3   5

          [1,2] = [](1x0)
          [1,3] = [](1x0)
        }
</pre></div>

<p><strong>See also:</strong> <a href="#XREFfindstr">findstr</a>, <a href="#XREFstrmatch">strmatch</a>, <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<a name="XREFstrjoin"></a><dl>
<dt><a name="index-strjoin"></a>Function File: <em><var>str</var> =</em> <strong>strjoin</strong> <em>(<var>cstr</var>)</em></dt>
<dt><a name="index-strjoin-1"></a>Function File: <em><var>str</var> =</em> <strong>strjoin</strong> <em>(<var>cstr</var>, <var>delimiter</var>)</em></dt>
<dd><p>Join the elements of the cell string array, <var>cstr</var>, into a single
string.
</p>
<p>If no <var>delimiter</var> is specified, the elements of <var>cstr</var>
separated by a space.
</p>
<p>If <var>delimiter</var> is specified as a string, the cell string array is
joined using the string.  Escape sequences are supported.
</p>
<p>If <var>delimiter</var> is a cell string array whose length is one less
than <var>cstr</var>, then the elements of <var>cstr</var> are joined by
interleaving the cell string elements of <var>delimiter</var>.  Escape
sequences are not supported.
</p>
<div class="example">
<pre class="example">strjoin ({'Octave','Scilab','Lush','Yorick'}, '*')
      &rArr; 'Octave*Scilab*Lush*Yorick'
</pre></div>

<p><strong>See also:</strong> strsplit.
</p></dd></dl>


<a name="XREFstrmatch"></a><dl>
<dt><a name="index-strmatch"></a>Function File: <em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>)</em></dt>
<dt><a name="index-strmatch-1"></a>Function File: <em></em> <strong>strmatch</strong> <em>(<var>s</var>, <var>A</var>, &quot;exact&quot;)</em></dt>
<dd><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>&quot;exact&quot;</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 (&quot;apple&quot;, &quot;apple juice&quot;)
     &rArr; 1

strmatch (&quot;apple&quot;, [&quot;apple  &quot;; &quot;apple juice&quot;; &quot;an apple&quot;])
     &rArr; [1; 2]

strmatch (&quot;apple&quot;, [&quot;apple  &quot;; &quot;apple juice&quot;; &quot;an apple&quot;], &quot;exact&quot;)
     &rArr; [1]
</pre></div>

<p><strong>Caution:</strong> <code>strmatch</code> is scheduled for deprecation.  Use
<code>strncmp</code> (normal case), or <code>strcmp</code> (<code>&quot;exact&quot;</code> case), or
<code>regexp</code> in all new code.
</p>
<p><strong>See also:</strong> <a href="#XREFstrfind">strfind</a>, <a href="#XREFfindstr">findstr</a>, <a href="Comparing-Strings.html#XREFstrcmp">strcmp</a>, <a href="Comparing-Strings.html#XREFstrncmp">strncmp</a>, <a href="Comparing-Strings.html#XREFstrcmpi">strcmpi</a>, <a href="Comparing-Strings.html#XREFstrncmpi">strncmpi</a>, <a href="Finding-Elements-and-Checking-Conditions.html#XREFfind">find</a>.
</p></dd></dl>


<a name="XREFstrtok"></a><dl>
<dt><a name="index-strtok"></a>Function File: <em>[<var>tok</var>, <var>rem</var>] =</em> <strong>strtok</strong> <em>(<var>str</var>)</em></dt>
<dt><a name="index-strtok-1"></a>Function File: <em>[<var>tok</var>, <var>rem</var>] =</em> <strong>strtok</strong> <em>(<var>str</var>, <var>delim</var>)</em></dt>
<dd>
<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>
<p>Examples:
</p>
<div class="example">
<pre class="example">strtok (&quot;this is the life&quot;)
     &rArr; &quot;this&quot;

[tok, rem] = strtok (&quot;14*27+31&quot;, &quot;+-*/&quot;)
     &rArr;
        tok = 14
        rem = *27+31
</pre></div>

<p><strong>See also:</strong> <a href="#XREFindex">index</a>, <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFstrchr">strchr</a>, <a href="Character-Class-Functions.html#XREFisspace">isspace</a>.
</p></dd></dl>


<a name="XREFstrsplit"></a><dl>
<dt><a name="index-strsplit"></a>Function File: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(<var>s</var>)</em></dt>
<dt><a name="index-strsplit-1"></a>Function File: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(<var>s</var>, <var>del</var>)</em></dt>
<dt><a name="index-strsplit-2"></a>Function File: <em>[<var>cstr</var>] =</em> <strong>strsplit</strong> <em>(&hellip;, <var>name</var>, <var>value</var>)</em></dt>
<dt><a name="index-strsplit-3"></a>Function File: <em>[<var>cstr</var>, <var>matches</var>] =</em> <strong>strsplit</strong> <em>(&hellip;)</em></dt>
<dd><p>Split the string <var>s</var> using the delimiters specified by <var>del</var>
and return a cell string array of substrings.  If a delimiter is not
specified the string, <var>s</var>, is split at whitespace.  The delimiter,
<var>del</var> may be a string, a scalar cell string, or cell string array.
By default, consecutive delimiters in the input string <var>s</var> are
collapsed into one.
</p>
<p>The second output, <var>matches</var>, returns the delimiters which were matched
in the original string.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">strsplit (&quot;a b c&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,b,c&quot;, &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a foo b,bar c&quot;, {&quot;\s&quot;, &quot;foo&quot;, &quot;bar&quot;})
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,,b, c&quot;, {&quot;,&quot;, &quot; &quot;}, false)
      &rArr;
          {
            [1,1] = a
            [1,2] = 
            [1,3] = b
            [1,4] = 
            [1,5] = c
          }

</pre></div>

<p>Supported <var>name</var>/<var>value</var> pair arguments are;
</p>
<ul>
<li> <var>collapsedelimiters</var> may take the value of <var>true</var> or
<var>false</var> with the default being <var>false</var>.

</li><li> <var>delimitertype</var> may take the value of <code>simple</code> or
<code>regularexpression</code>.  The default is <var>delimitertype</var> is
<code>simple</code>.
</li></ul>

<p>Example:
</p>
<div class="example">
<pre class="example">strsplit (&quot;a foo b,bar c&quot;, &quot;,|\\s|foo|bar&quot;, &quot;delimitertype&quot;, &quot;regularexpression&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,,b, c&quot;, &quot;[, ]&quot;, false, &quot;delimitertype&quot;, &quot;regularexpression&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = 
            [1,3] = b
            [1,4] = 
            [1,5] = c
          }

strsplit (&quot;a,\t,b, c&quot;, {',', '\s'}, &quot;delimitertype&quot;, &quot;regularexpression&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

strsplit (&quot;a,\t,b, c&quot;, {',', ' ', '\t'}, &quot;collapsedelimiters&quot;, false)
      &rArr;
          {
            [1,1] = a
            [1,2] = 
            [1,3] = 
            [1,4] = b
            [1,5] = 
            [1,6] = c
          }
</pre></div>


<p><strong>See also:</strong> <a href="#XREFostrsplit">ostrsplit</a>, <a href="#XREFstrjoin">strjoin</a>, <a href="#XREFstrtok">strtok</a>, <a href="#XREFregexp">regexp</a>.
</p></dd></dl>


<a name="XREFostrsplit"></a><dl>
<dt><a name="index-ostrsplit"></a>Function File: <em>[<var>cstr</var>] =</em> <strong>ostrsplit</strong> <em>(<var>s</var>, <var>sep</var>)</em></dt>
<dt><a name="index-ostrsplit-1"></a>Function File: <em>[<var>cstr</var>] =</em> <strong>ostrsplit</strong> <em>(<var>s</var>, <var>sep</var>, <var>strip_empty</var>)</em></dt>
<dd><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>
<p>2-D character arrays are split at separators and at the original column
boundaries.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">ostrsplit (&quot;a,b,c&quot;, &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = c
          }

ostrsplit ([&quot;a,b&quot; ; &quot;cde&quot;], &quot;,&quot;)
      &rArr;
          {
            [1,1] = a
            [1,2] = b
            [1,3] = cde
          }
</pre></div>

<p><strong>See also:</strong> <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFstrtok">strtok</a>.
</p></dd></dl>


<a name="XREFstrread"></a><dl>
<dt><a name="index-strread"></a>Function File: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>)</em></dt>
<dt><a name="index-strread-1"></a>Function File: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>)</em></dt>
<dt><a name="index-strread-2"></a>Function File: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>format_repeat</var>)</em></dt>
<dt><a name="index-strread-3"></a>Function File: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>prop1</var>, <var>value1</var>, &hellip;)</em></dt>
<dt><a name="index-strread-4"></a>Function File: <em>[<var>a</var>, &hellip;] =</em> <strong>strread</strong> <em>(<var>str</var>, <var>format</var>, <var>format_repeat</var>, <var>prop1</var>, <var>value1</var>, &hellip;)</em></dt>
<dd><p>Read data from a string.
</p>
<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>
<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:
</p>
<dl compact="compact">
<dt><code>%s</code></dt>
<dd><p>The word is parsed as a string.
</p>
</dd>
<dt><code>%f</code></dt>
<dt><code>%n</code></dt>
<dd><p>The word is parsed as a number and converted to double.
</p>
</dd>
<dt><code>%d</code></dt>
<dt><code>%u</code></dt>
<dd><p>The word is parsed as a number and converted to int32.
</p>
</dd>
<dt><code>%*', '%*f', '%*s</code></dt>
<dd><p>The word is skipped.
</p>
<p>For %s and %d, %f, %n, %u and the associated %*s &hellip; 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.
</p>
</dd>
<dt><code>literals</code></dt>
<dd><p>In addition the format may contain literal character strings; these will be
skipped during reading.
</p></dd>
</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>
<p>By default, <var>format</var> is <tt>&quot;%f&quot;</tt>, meaning that numbers are read from
<var>str</var>.  This will do if <var>str</var> contains only numeric fields.
</p>
<p>For example, the string
</p>
<div class="example">
<pre class="example"><var>str</var> = &quot;\
Bunny Bugs   5.5\n\
Duck Daffy  -7.5e-5\n\
Penguin Tux   6&quot;
</pre></div>

<p>can be read using
</p>
<div class="example">
<pre class="example">[<var>a</var>, <var>b</var>, <var>c</var>] = strread (<var>str</var>, &quot;%s %s %f&quot;);
</pre></div>

<p>Optional numeric argument <var>format_repeat</var> can be used for
limiting the number of items read:
</p>
<dl compact="compact">
<dt>-1</dt>
<dd><p>(default) read all of the string until the end.
</p>
</dd>
<dt>N</dt>
<dd><p>Read N times <var>nargout</var> items.  0 (zero) is an acceptable
value for <var>format_repeat</var>.
</p></dd>
</dl>

<p>The behavior of <code>strread</code> can be changed via property-value
pairs.  The following properties are recognized:
</p>
<dl compact="compact">
<dt><code>&quot;commentstyle&quot;</code></dt>
<dd><p>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.
</p>
<ul>
<li> <code>&quot;shell&quot;</code>
Everything from <code>#</code> characters to the nearest end-of-line is skipped.

</li><li> <code>&quot;c&quot;</code>
Everything between <code>/*</code> and <code>*/</code> is skipped.

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

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

</li><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.
</li></ul>

</dd>
<dt><code>&quot;delimiter&quot;</code></dt>
<dd><p>Any character in <var>value</var> will be used to split <var>str</var> into words
(default value = any whitespace).
</p>
</dd>
<dt><code>&quot;emptyvalue&quot;</code>:</dt>
<dd><p>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.
</p>
</dd>
<dt><code>&quot;multipledelimsasone&quot;</code></dt>
<dd><p>Treat a series of consecutive delimiters, without whitespace in between,
as a single delimiter.  Consecutive delimiter series need not be vertically
<code>&quot;aligned&quot;</code>.
</p>
</dd>
<dt><code>&quot;treatasempty&quot;</code></dt>
<dd><p>Treat single occurrences (surrounded by delimiters or whitespace) of the
string(s) in <var>value</var> as missing values.
</p>
</dd>
<dt><code>&quot;returnonerror&quot;</code></dt>
<dd><p>If <var>value</var> true (1, default), ignore read errors and return normally.
If false (0), return an error.
</p>
</dd>
<dt><code>&quot;whitespace&quot;</code></dt>
<dd><p>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 = <code>&quot; \b\r\n\t&quot;</code> (note the space).
Unless whitespace is set to &rdquo; (empty) AND at least one <code>&quot;%s&quot;</code> format
conversion specifier is supplied, a space is always part of whitespace.
</p>
</dd>
</dl>

<p>When the number of words in <var>str</var> doesn&rsquo;t match an exact multiple
of the number of format conversion specifiers, strread&rsquo;s behavior
depends on the last character of <var>str</var>:
</p>
<dl compact="compact">
<dt>last character = <code>&quot;\n&quot;</code></dt>
<dd><p>Data columns are padded with empty fields or Nan so that all columns
have equal length 
</p>
</dd>
<dt>last character is not <code>&quot;\n&quot;</code></dt>
<dd><p>Data columns are not padded; strread returns columns of unequal length
</p>
</dd>
</dl>


<p><strong>See also:</strong> <a href="Simple-File-I_002fO.html#XREFtextscan">textscan</a>, <a href="Simple-File-I_002fO.html#XREFtextread">textread</a>, <a href="Simple-File-I_002fO.html#XREFload">load</a>, <a href="Simple-File-I_002fO.html#XREFdlmread">dlmread</a>, <a href="Formatted-Input.html#XREFfscanf">fscanf</a>.
</p></dd></dl>


<a name="XREFstrrep"></a><dl>
<dt><a name="index-strrep"></a>Built-in Function: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(<var>str</var>, <var>ptn</var>, <var>rep</var>)</em></dt>
<dt><a name="index-strrep-1"></a>Built-in Function: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(<var>cellstr</var>, <var>ptn</var>, <var>rep</var>)</em></dt>
<dt><a name="index-strrep-2"></a>Built-in Function: <em><var>newstr</var> =</em> <strong>strrep</strong> <em>(&hellip;, &quot;overlaps&quot;, <var>val</var>)</em></dt>
<dd><p>Replace all occurrences of the pattern <var>ptn</var> in the string <var>str</var>
with the string <var>rep</var> and return the result.
</p>
<p>The optional argument <code>&quot;overlaps&quot;</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><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.
</p>
<p>Example:
</p>
<div class="example">
<pre class="example">strrep (&quot;This is a test string&quot;, &quot;is&quot;, &quot;&amp;%$&quot;)
    &rArr;  &quot;Th&amp;%$ &amp;%$ a test string&quot;
</pre></div>


<p><strong>See also:</strong> <a href="#XREFregexprep">regexprep</a>, <a href="#XREFstrfind">strfind</a>, <a href="#XREFfindstr">findstr</a>.
</p></dd></dl>


<a name="XREFsubstr"></a><dl>
<dt><a name="index-substr"></a>Function File: <em></em> <strong>substr</strong> <em>(<var>s</var>, <var>offset</var>)</em></dt>
<dt><a name="index-substr-1"></a>Function File: <em></em> <strong>substr</strong> <em>(<var>s</var>, <var>offset</var>, <var>len</var>)</em></dt>
<dd><p>Return the substring of <var>s</var> which starts at character number
<var>offset</var> and is <var>len</var> characters long.
</p>
<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>
<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>
<p>Examples:
</p>
<div class="example">
<pre class="example">substr (&quot;This is a test string&quot;, 6, 9)
     &rArr; &quot;is a test&quot;
substr (&quot;This is a test string&quot;, -11)
     &rArr; &quot;test string&quot;
substr (&quot;This is a test string&quot;, -11, -7)
     &rArr; &quot;test&quot;
</pre></div>

<p>This function is patterned after the equivalent function in Perl.
</p></dd></dl>


<a name="XREFregexp"></a><dl>
<dt><a name="index-regexp"></a>Built-in Function: <em>[<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>, <var>sp</var>] =</em> <strong>regexp</strong> <em>(<var>str</var>, <var>pat</var>)</em></dt>
<dt><a name="index-regexp-1"></a>Built-in Function: <em>[&hellip;] =</em> <strong>regexp</strong> <em>(<var>str</var>, <var>pat</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd><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>
<p>The matched pattern <var>pat</var> can include any of the standard regex
operators, including:
</p>
<dl compact="compact">
<dt><code>.</code></dt>
<dd><p>Match any character
</p>
</dd>
<dt><code>* + ? {}</code></dt>
<dd><p>Repetition operators, representing
</p>
<dl compact="compact">
<dt><code>*</code></dt>
<dd><p>Match zero or more times
</p>
</dd>
<dt><code>+</code></dt>
<dd><p>Match one or more times
</p>
</dd>
<dt><code>?</code></dt>
<dd><p>Match zero or one times
</p>
</dd>
<dt><code>{<var>n</var>}</code></dt>
<dd><p>Match exactly <var>n</var> times
</p>
</dd>
<dt><code>{<var>n</var>,}</code></dt>
<dd><p>Match <var>n</var> or more times
</p>
</dd>
<dt><code>{<var>m</var>,<var>n</var>}</code></dt>
<dd><p>Match between <var>m</var> and <var>n</var> times
</p></dd>
</dl>

</dd>
<dt><code>[&hellip;] [^&hellip;]</code></dt>
<dd>
<p>List operators.  The pattern will match any character listed between &quot;[&quot;
and &quot;]&quot;.  If the first character is &quot;^&quot; then the pattern is inverted and
any character except those listed between brackets will match.
</p>
<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>.
</p>
</dd>
<dt><code>() (?:)</code></dt>
<dd><p>Grouping operator.  The first form, parentheses only, also creates a token.
</p>
</dd>
<dt><code>|</code></dt>
<dd><p>Alternation operator.  Match one of a choice of regular expressions.  The
alternatives must be delimited by the grouping operator <code>()</code> above.
</p>
</dd>
<dt><code>^ $</code></dt>
<dd><p>Anchoring operators.  Requires pattern to occur at the start (<code>^</code>) or
end (<code>$</code>) of the string.
</p></dd>
</dl>

<p>In addition, the following escaped characters have special meaning.
</p>
<dl compact="compact">
<dt><code>\d</code></dt>
<dd><p>Match any digit
</p>
</dd>
<dt><code>\D</code></dt>
<dd><p>Match any non-digit
</p>
</dd>
<dt><code>\s</code></dt>
<dd><p>Match any whitespace character
</p>
</dd>
<dt><code>\S</code></dt>
<dd><p>Match any non-whitespace character
</p>
</dd>
<dt><code>\w</code></dt>
<dd><p>Match any word character
</p>
</dd>
<dt><code>\W</code></dt>
<dd><p>Match any non-word character
</p>
</dd>
<dt><code>\&lt;</code></dt>
<dd><p>Match the beginning of a word
</p>
</dd>
<dt><code>\&gt;</code></dt>
<dd><p>Match the end of a word
</p>
</dd>
<dt><code>\B</code></dt>
<dd><p>Match within a word
</p></dd>
</dl>

<p>Implementation Note: For compatibility with <small>MATLAB</small>, ordinary escape
sequences (e.g., <code>&quot;\n&quot;</code> =&gt; newline) are processed in <var>pat</var>
regardless of whether <var>pat</var> has been defined within single quotes.  Use
a second backslash to stop interpolation of the escape sequence (e.g.,
&quot;\\n&quot;) or use the <code>regexptranslate</code> function.
</p>
<p>The outputs of <code>regexp</code> default to the order given below
</p>
<dl compact="compact">
<dt><var>s</var></dt>
<dd><p>The start indices of each matching substring
</p>
</dd>
<dt><var>e</var></dt>
<dd><p>The end indices of each matching substring
</p>
</dd>
<dt><var>te</var></dt>
<dd><p>The extents of each matched token surrounded by <code>(&hellip;)</code> in
<var>pat</var>
</p>
</dd>
<dt><var>m</var></dt>
<dd><p>A cell array of the text of each match
</p>
</dd>
<dt><var>t</var></dt>
<dd><p>A cell array of the text of each token matched
</p>
</dd>
<dt><var>nm</var></dt>
<dd><p>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;&hellip;)</code>.
</p>
</dd>
<dt><var>sp</var></dt>
<dd><p>A cell array of the text not returned by match, i.e., what remains if you
split the string based on <var>pat</var>.
</p></dd>
</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>
<tr><td width="20%"></td><td width="30%"><code>'start'</code></td><td width="30%"><var>s</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'end'</code></td><td width="30%"><var>e</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'tokenExtents'</code></td><td width="30%"><var>te</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'match'</code></td><td width="30%"><var>m</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'tokens'</code></td><td width="30%"><var>t</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'names'</code></td><td width="30%"><var>nm</var></td><td width="20%"></td></tr>
<tr><td width="20%"></td><td width="30%"><code>'split'</code></td><td width="30%"><var>sp</var></td><td width="20%"></td></tr>
</table>

<p>Additional arguments are summarized below.
</p>
<dl compact="compact">
<dt>&lsquo;<samp>once</samp>&rsquo;</dt>
<dd><p>Return only the first occurrence of the pattern.
</p>
</dd>
<dt>&lsquo;<samp>matchcase</samp>&rsquo;</dt>
<dd><p>Make the matching case sensitive.  (default)
</p>
<p>Alternatively, use (?-i) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>ignorecase</samp>&rsquo;</dt>
<dd><p>Ignore case when matching the pattern to the string.
</p>
<p>Alternatively, use (?i) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>stringanchors</samp>&rsquo;</dt>
<dd><p>Match the anchor characters at the beginning and end of the string.
(default)
</p>
<p>Alternatively, use (?-m) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>lineanchors</samp>&rsquo;</dt>
<dd><p>Match the anchor characters at the beginning and end of the line.
</p>
<p>Alternatively, use (?m) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>dotall</samp>&rsquo;</dt>
<dd><p>The pattern <code>.</code> matches all characters including the newline character.
 (default)
</p>
<p>Alternatively, use (?s) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>dotexceptnewline</samp>&rsquo;</dt>
<dd><p>The pattern <code>.</code> matches all characters except the newline character.
</p>
<p>Alternatively, use (?-s) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>literalspacing</samp>&rsquo;</dt>
<dd><p>All characters in the pattern, including whitespace, are significant and are
used in pattern matching.  (default)
</p>
<p>Alternatively, use (?-x) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>freespacing</samp>&rsquo;</dt>
<dd><p>The pattern may include arbitrary whitespace and also comments beginning with
the character &lsquo;<samp>#</samp>&rsquo;.
</p>
<p>Alternatively, use (?x) in the pattern.
</p>
</dd>
<dt>&lsquo;<samp>noemptymatch</samp>&rsquo;</dt>
<dd><p>Zero-length matches are not returned.  (default)
</p>
</dd>
<dt>&lsquo;<samp>emptymatch</samp>&rsquo;</dt>
<dd><p>Return zero-length matches.
</p>
<p><code>regexp ('a', 'b*', 'emptymatch')</code> returns <code>[1 2]</code> because there
are zero or more <code>'b'</code> characters at positions 1 and end-of-string.
</p>
</dd>
</dl>

<p><strong>See also:</strong> <a href="#XREFregexpi">regexpi</a>, <a href="#XREFstrfind">strfind</a>, <a href="#XREFregexprep">regexprep</a>.
</p></dd></dl>


<a name="XREFregexpi"></a><dl>
<dt><a name="index-regexpi"></a>Built-in Function: <em>[<var>s</var>, <var>e</var>, <var>te</var>, <var>m</var>, <var>t</var>, <var>nm</var>, <var>sp</var>] =</em> <strong>regexpi</strong> <em>(<var>str</var>, <var>pat</var>)</em></dt>
<dt><a name="index-regexpi-1"></a>Built-in Function: <em>[&hellip;] =</em> <strong>regexpi</strong> <em>(<var>str</var>, <var>pat</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd>
<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="#XREFregexp">regexp</a>, for details on the
syntax of the search pattern.
</p>
<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>.
</p></dd></dl>


<a name="XREFregexprep"></a><dl>
<dt><a name="index-regexprep"></a>Built-in Function: <em><var>outstr</var> =</em> <strong>regexprep</strong> <em>(<var>string</var>, <var>pat</var>, <var>repstr</var>)</em></dt>
<dt><a name="index-regexprep-1"></a>Built-in Function: <em><var>outstr</var> =</em> <strong>regexprep</strong> <em>(<var>string</var>, <var>pat</var>, <var>repstr</var>, &quot;<var>opt1</var>&quot;, &hellip;)</em></dt>
<dd><p>Replace occurrences of pattern <var>pat</var> in <var>string</var> with <var>repstr</var>.
</p>
<p>The pattern is a regular expression as documented for <code>regexp</code>.
See <a href="#XREFregexp">regexp</a>.
</p>
<p>The replacement string may contain <code>$i</code>, which substitutes
for the ith set of parentheses in the match string.  For example,
</p>
<div class="example">
<pre class="example">regexprep (&quot;Bill Dunn&quot;, '(\w+) (\w+)', '$2, $1')
</pre></div>

<p>returns &quot;Dunn, Bill&quot;
</p>
<p>Options in addition to those of <code>regexp</code> are
</p>
<dl compact="compact">
<dt>&lsquo;<samp>once</samp>&rsquo;</dt>
<dd><p>Replace only the first occurrence of <var>pat</var> in the result.
</p>
</dd>
<dt>&lsquo;<samp>warnings</samp>&rsquo;</dt>
<dd><p>This option is present for compatibility but is ignored.
</p>
</dd>
</dl>

<p>Implementation Note: For compatibility with <small>MATLAB</small>, ordinary escape
sequences (e.g., <code>&quot;\n&quot;</code> =&gt; newline) are processed in both <var>pat</var>
and <var>repstr</var> regardless of whether they were defined within single
quotes.  Use a second backslash to stop interpolation of the escape sequence
(e.g., &quot;\\n&quot;) or use the <code>regexptranslate</code> function.
</p>
<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="#XREFstrrep">strrep</a>.
</p></dd></dl>


<a name="XREFregexptranslate"></a><dl>
<dt><a name="index-regexptranslate"></a>Function File: <em></em> <strong>regexptranslate</strong> <em>(<var>op</var>, <var>s</var>)</em></dt>
<dd><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
</p>
<dl compact="compact">
<dt><code>&quot;wildcard&quot;</code></dt>
<dd><p>The wildcard characters <code>.</code>, <code>*</code>, and <code>?</code> are replaced
with wildcards that are appropriate for a regular expression.
For example:
</p>
<div class="example">
<pre class="example">regexptranslate (&quot;wildcard&quot;, &quot;*.m&quot;)
     &rArr; &quot;.*\.m&quot;
</pre></div>

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

</dd>
</dl>

<p><strong>See also:</strong> <a href="#XREFregexp">regexp</a>, <a href="#XREFregexpi">regexpi</a>, <a href="#XREFregexprep">regexprep</a>.
</p></dd></dl>


<a name="XREFuntabify"></a><dl>
<dt><a name="index-untabify"></a>Function File: <em></em> <strong>untabify</strong> <em>(<var>t</var>)</em></dt>
<dt><a name="index-untabify-1"></a>Function File: <em></em> <strong>untabify</strong> <em>(<var>t</var>, <var>tw</var>)</em></dt>
<dt><a name="index-untabify-2"></a>Function File: <em></em> <strong>untabify</strong> <em>(<var>t</var>, <var>tw</var>, <var>deblank</var>)</em></dt>
<dd><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>
<p>If the optional argument <var>deblank</var> is true, then the spaces will
be removed from the end of the character data.
</p>
<p>The following example reads a file and writes an untabified version
of the same file with trailing spaces stripped.
</p>
<div class="example">
<pre class="example">fid = fopen (&quot;tabbed_script.m&quot;);
text = char (fread (fid, &quot;uchar&quot;)');
fclose (fid);
fid = fopen (&quot;untabified_script.m&quot;, &quot;w&quot;);
text = untabify (strsplit (text, &quot;\n&quot;), 8, true);
fprintf (fid, &quot;%s\n&quot;, text{:});
fclose (fid);
</pre></div>


<p><strong>See also:</strong> <a href="String-Conversions.html#XREFstrjust">strjust</a>, <a href="#XREFstrsplit">strsplit</a>, <a href="#XREFdeblank">deblank</a>.
</p></dd></dl>


<hr>
<div class="header">
<p>
Next: <a href="String-Conversions.html#String-Conversions" accesskey="n" rel="next">String Conversions</a>, Previous: <a href="Comparing-Strings.html#Comparing-Strings" accesskey="p" rel="prev">Comparing Strings</a>, Up: <a href="Strings.html#Strings" accesskey="u" rel="up">Strings</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>