summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/xstring/xstring_doc_en.tex
blob: aa1dae5525caf06a02360d7f6c630038b032d1fe (plain)
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
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
% This is xtring_doc_en.tex, the manual of xstring
% Christian Tellechea 2008
%
% email : unbonpetit@gmail.com
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%
%     http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[dvips,colorlinks=true,hyperfootnotes=false,citecolor=black,filecolor=black,linkcolor=blue,urlcolor=blue,bookmarks=false,pdfauthor={Christian Tellechea},pdftitle={xstring},pdfsubject={package for strings},pdfkeywords={xstring,latex,string},pdfcreator={LaTeX}]{hyperref}
\usepackage[a4paper,dvips,margin=1.9cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{textcomp}
\usepackage{moreverb}
\usepackage{lmodern}
\usepackage{eurosym}
\usepackage{xspace}
\usepackage{xstring}
\usepackage{xstring}
\usepackage[french,english]{babel}
\makeatletter
\newcommand*\exemple{\@ifstar{\def\frontiere{|}\@xs@MakeVerb}{\def\frontiere{}\@xs@MakeVerb}}
\long\def\@xs@afterreadverb#1{%
	\normalexpandarg
	\tokenize\cs@resultat{#1}%
	\fullexpandarg
	\leavevmode\hbox to0.7\linewidth{\hfil\tt#1}\quad\frontiere\cs@resultat\frontiere\hfil\par}
\makeatother
\newcommand\guill[1]{"#1"}
\newcommand\argu[1]{$\langle$\textit{#1}$\rangle$}
\newcommand\ARGU[1]{\texttt{\{}\argu{#1}\texttt{\}}}
\newcommand\arguC[1]{\texttt{[}\argu{#1}\texttt{]}}
\newcommand\arguCC[2]{\texttt{[}\argu{#1}{,}\argu{#2}\texttt{]}}
\newcommand\texte[1]{\texttt{text}${}_{#1}$}
\newcommand\etoile{$\langle$\texttt{[*]}$\rangle$}
\newenvironment{Conditions}[1][1cm]%
{\begin{list}%
	{$\vartriangleright$}%
	{\setlength{\leftmargin}{#1}
	 \setlength{\itemsep}{0pt}
	 \setlength{\parsep}{0pt}
	 \setlength{\topsep}{2ptplus3ptminus2pt}
	}}%
{\end{list}}
\renewcommand\th{${}^\text{th}$\xspace}
\newcommand\US{syntax unit\xspace}
\newcommand\USs{syntax units\xspace}
\newcommand\Xstring{\textsf{xstring}\xspace}

\begin{document}
\setlength{\parindent}{0pt}
\begin{titlepage}
	\null\par\vfill
	\begin{center}
		\begin{minipage}{0.75\linewidth}
			\begin{center}
				\Huge\bfseries xstring\par\vspace{5pt}
				\small v\xstringversion\par\vspace{25pt}
				\normalsize User's manual
			\end{center}
		\end{minipage}
	\end{center}
	\vspace{1cm}
	\begin{center}
		Christian {\sc Tellechea}\par\small
		\href{mailto:unbonpetit@gmail.com}{\nolinkurl{unbonpetit@gmail.com}}\par\vspace{5pt}
		\xstringenglishdate
	\end{center}
	\vfill\hrulefill
	\begin{center}
		\begin{minipage}{0.85\linewidth}
			\noindent
			\hfill\textbf{\textit{Abstract}}\hfill{}\medskip\par
			This package which requires $\varepsilon$-\TeX{}, provides macros manipulating strings contaning chars, control sequences, groups between braces and other special tokens so that the macros may be used for programming purposes. Main features are
			\parindent1.5em
			\begin{itemize}
				\item[$\triangleright$] tests:
					\begin{itemize}
						\item does a string contains at least $n$ times an another?
						\item does a string starts (or ends) with another? etc.
						\item is a string an integer? A decimal?
						\item are 2 strings equal?
					\end{itemize}
				\item[$\triangleright$] extractions of substrings:
					\begin{itemize}
						\item what is on the left (or the right) of the $n$\th occurrence of a substring;
						\item what is between the occurrences of 2 substrings;
						\item substring between 2 positions, etc.
					\end{itemize}
				\item[$\triangleright$] substitution of all, or the $n$ first occurrences of a substring for an other substring;
				\item[$\triangleright$] calculation of numbers:
					\begin{itemize}
						\item length of a string;
						\item position of the $n$\th occurrence of a substring;
						\item how many times a string contains a substring?
						\item comparison of 2 strings: position of the first difference.
					\end{itemize}
			\end{itemize}
			\parindent0pt
			\medskip
			Other macros allow to use special characters forbiden in arguments (\verb|#| and \verb|%|) and manage differences between catcodes for advanced programming purposes.
		\end{minipage}
	\end{center}
	\hrulefill\vfill{}
\end{titlepage}
\pagebreak
\tableofcontents
\pagebreak

This manual is a translation of the french manual. I apologize for my poor english but I did my best\footnote{Any email to tell me errors would be appreciated!}, and I hope that the following is comprehensible!
\section{Presentation}
\subsection{Description}
This extension\footnote{This extension does not require \LaTeX{} and can be compiled with Plain $\varepsilon$-\TeX{}.} provides macros and tests operating on strings of \TeX{} code, as other programmation languages have. They provides the usual strings operations, such as: test if a string contains another, begins or ends with another, extractions of strings, calculation of the position of a substring, of the number of occurrences, etc.\medskip


\Xstring reads the arguments of the macros \US by \US\footnote{In the \TeX{} code, a \US is a control sequence, a group between brace or a single char. See also page~\pageref{developpementarguments}.} : when \USs are \guill{simple} chars (catcode 10, 11 and 12), \Xstring logically read the argument char by char. \Xstring can also be used for programming purpose, including in arguments other tokens such as control sequences, braces and tokens with other catcodes. See chapter on reading mode and arguments expansion (page~\pageref{developpementarguments}), the command \verb|\verbtocs| (page~\pageref{verbtocs}) and the command \verb|\scancs| (page~\pageref{scancs}).\medskip

As the arguments may contain chars, advanced users could have problems with catcodes leading to unexpected behaviours. These behaviours can be controlled: read page~\pageref{macrosetoilees}.\medskip

Certainly, other packages exist (for example \href{http://www.ctan.org/tex-archive/macros/latex/contrib/substr/}{\nolinkurl{substr}} and \href{http://www.ctan.org/tex-archive/macros/latex/contrib/stringstrings/}{\nolinkurl{stringstrings}}), but as well as differences on features, they do not take into account occurrences so I found them too limited and difficult to use for programming.

\subsection{Motivation}
I decided to write this package of macros because I have never really found tools in \LaTeX{} suiting my needs for strings. So, over the last few months, I wrote a few macros that I occasionally or regularly used. Their numbers have increased and become a little too dispersed in directories in my computer, so I have grouped them together in this package.

Thus, writing a coherent set of macros forces more discipline and leads to necessary improvements, which took most of the time I spent writing this package. This package is my first one as I recently discoverd \LaTeX{}\footnote{In november 2007, I will be a noob for a long time\ldots}, so my main motivation was to make progress in programming with \TeX, and to tackle its specific methods.

\section{The macros}
\subsection{Presentation of macros}
In the following chapters, all the macros will be presented this plan:
\begin{itemize}
	\item the syntax\footnote{The optional star, the optional argument in last position will be explained later. See page~\pageref{macrosetoilees} for starred macros and  page~\pageref{argumentoptionnel} for the optional argument.} and the value of optional arguments
	\item a short description of the operation;
	\item the operation under special conditions. For each conditions considered, the operation described has priority on that (those) below;
	\item finally, several examples\footnote{For much more examples, see the test file.} are given. I tried to find them most easily comprehensible and most representative of the situations met in normal use. If a doubt is possible with spaces in the result, this one will be delimited by \guill{|}, given that an empty string is represented by \guill{||}.
\end{itemize}

\subsection{The tests}
\subsubsection{\ttfamily\textbackslash IfSubStr}
\verb|\IfSubStr|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip

The value of the optional argument \argu{number} is 1 by default.\par\smallskip

Tests if \argu{string} contains at least \argu{number} times \argu{stringA} and runs \argu{true} if so, and \argu{false} otherwise.\medskip

\begin{Conditions}
\item If \argu{number}${}\leqslant0$, runs \argu{false};
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}

\exemple|\IfSubStr{xstring}{tri}{true}{false}|
\exemple|\IfSubStr{xstring}{a}{true}{false}|
\exemple|\IfSubStr{a bc def }{c d}{true}{false}|
\exemple|\IfSubStr{a bc def }{cd}{true}{false}|
\exemple|\IfSubStr[2]{1a2a3a}{a}{true}{false}|
\exemple|\IfSubStr[3]{1a2a3a}{a}{true}{false}|
\exemple|\IfSubStr[4]{1a2a3a}{a}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfSubStrBefore}
\verb|\IfSubStrBefore|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip

The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip

In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is on the left of the \argu{number2}\th occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip

\begin{Conditions}
\item If one of the occurrences is not found, it runs \argu{false};
\item If one of the arguments \argu{string}, \argu{stringA} or \argu{stringB} is empty, runs \argu{false};
\item If one of the optional arguments is negative or zero, runs \argu{false}.
\end{Conditions}

\exemple|\IfSubStrBefore{xstring}{st}{in}{true}{false}|
\exemple|\IfSubStrBefore{xstring}{ri}{s}{true}{false}|
\exemple|\IfSubStrBefore{LaTeX}{LaT}{TeX}{true}{false}|
\exemple|\IfSubStrBefore{a bc def }{ b}{ef}{true}{false}|
\exemple|\IfSubStrBefore{a bc def }{ab}{ef}{true}{false}|
\exemple|\IfSubStrBefore[2,1]{b1b2b3}{b}{2}{true}{false}|
\exemple|\IfSubStrBefore[3,1]{b1b2b3}{b}{2}{true}{false}|
\exemple|\IfSubStrBefore[2,2]{baobab}{a}{b}{true}{false}|
\exemple|\IfSubStrBefore[2,3]{baobab}{a}{b}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfSubStrBehind}

\verb|\IfSubStrBehind|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip

The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip

In \argu{string}, tests if the \argu{number1}\th occurrence of \argu{stringA} is on the right of the \argu{number2}\th occurrence of \argu{stringB}. Runs \argu{true} if so, and \argu{false} otherwise.\medskip

\begin{Conditions}
\item If one of the occurrences is not found, it runs \argu{false};
\item If one of the arguments \argu{string}, \argu{stringA} or \argu{stringB} is empty, runs \argu{false};
\item If one of the optional arguments is negative or zero, runs \argu{false}.
\end{Conditions}

\exemple|\IfSubStrBehind{xstring}{ri}{xs}{true}{false}|
\exemple|\IfSubStrBehind{xstring}{s}{i}{true}{false}|
\exemple|\IfSubStrBehind{LaTeX}{TeX}{LaT}{true}{false}|
\exemple|\IfSubStrBehind{a bc def }{ d}{a}{true}{false}|
\exemple|\IfSubStrBehind{a bc def }{cd}{a b}{true}{false}|
\exemple|\IfSubStrBehind[2,1]{b1b2b3}{b}{2}{true}{false}|
\exemple|\IfSubStrBehind[3,1]{b1b2b3}{b}{2}{true}{false}|
\exemple|\IfSubStrBehind[2,2]{baobab}{b}{a}{true}{false}|
\exemple|\IfSubStrBehind[2,3]{baobab}{b}{a}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfBeginWith}

\verb|\IfBeginWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{true}\ARGU{false}
\smallskip

Tests if \argu{string} begins with \argu{stringA}, and runs \argu{true} if so, and \argu{false} otherwise.\medskip

\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}

\exemple|\IfBeginWith{xstring}{xst}{true}{false}|
\exemple|\IfBeginWith{LaTeX}{a}{true}{false}|
\exemple|\IfBeginWith{a bc def }{a b}{true}{false}|
\exemple|\IfBeginWith{a bc def }{ab}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfEndWith}

\verb|\IfEndWith|\etoile\ARGU{string}\ARGU{stringA}\ARGU{Behind}\ARGU{false}
\smallskip

Tests if \argu{string} ends with \argu{stringA}, and runs \argu{true} if so, and \argu{false} otherwise.\medskip

\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, runs \argu{false}.
\end{Conditions}

\exemple|\IfEndWith{xstring}{ring}{true}{false}|
\exemple|\IfEndWith{LaTeX}{a}{true}{false}|
\exemple|\IfEndWith{a bc def }{ef }{true}{false}|
\exemple|\IfEndWith{a bc def }{ef}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfInteger}

\verb|\IfInteger|\etoile\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip

Tests if \argu{number} is an integer, and runs \argu{true} if so, and \argu{false} otherwise.\smallskip

If test is false because unexpected characters, the control sequence \verb|\@xs@afterinteger| contains the illegal part of \argu{number}.\medskip

\exemple|\IfInteger{13}{true}{false}|
\exemple|\IfInteger{-219}{true}{false}|
\exemple|\IfInteger{+9}{true}{false}|
\exemple|\IfInteger{3.14}{true}{false}|
\exemple|\IfInteger{0}{true}{false}|
\exemple|\IfInteger{49a}{true}{false}|
\exemple|\IfInteger{+}{true}{false}|
\exemple|\IfInteger{-}{true}{false}|
\exemple|\IfInteger{0000}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfDecimal}\label{ifdecimal}

\verb|\IfDecimal|\etoile\ARGU{number}\ARGU{true}\ARGU{false}
\smallskip

Tests if \argu{number} is a decimal, and runs \argu{true} if so, and \argu{false} otherwise.\smallskip

Counters \verb|\integerpart| and \verb|\decimalpart| contain the integer part and decimal part of \argu{number}.

If test is false because unexpected characters, the control sequence \verb|\@xs@afterdecimal| contains the illegal part of \argu{number}, whereas if test is false because decimal part is empty after decimal separator, it contains "X".\medskip

\begin{Conditions}
	\item Decimal separator can be a dot or a comma;
	\item If what is on the right of decimal separator (if it exists) is empty, the test is false;
	\item If what is on the left of decimal separator (if it exists) is empty, the integer part is assumed to be 0;
\end{Conditions}

\exemple|\IfDecimal{3.14}{true}{false}|
\exemple|\IfDecimal{3,14}{true}{false}|
\exemple|\IfDecimal{-0.5}{true}{false}|
\exemple|\IfDecimal{.7}{true}{false}|
\exemple|\IfDecimal{,9}{true}{false}|
\exemple|\IfDecimal{1..2}{true}{false}|
\exemple|\IfDecimal{+6}{true}{false}|
\exemple|\IfDecimal{-15}{true}{false}|
\exemple|\IfDecimal{1.}{true}{false}|
\exemple|\IfDecimal{2,}{true}{false}|
\exemple|\IfDecimal{.}{true}{false}|
\exemple|\IfDecimal{,}{true}{false}|
\exemple|\IfDecimal{+}{true}{false}|
\exemple|\IfDecimal{-}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfStrEq}

\verb|\IfStrEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip

Tests if the strings \argu{stringA} and \argu{stringB} are equal, i.e. if they contain successively the same characters in the same order. Runs \argu{true} if so, and \argu{false} otherwise.\smallskip

\exemple|\IfStrEq{a1b2c3}{a1b2c3}{true}{false}|
\exemple|\IfStrEq{abcdef}{abcd}{true}{false}|
\exemple|\IfStrEq{abc}{abcdef}{true}{false}|
\exemple|\IfStrEq{3,14}{3,14}{true}{false}|
\exemple|\IfStrEq{12.34}{12.340}{true}{false}|
\exemple|\IfStrEq{abc}{}{true}{false}|
\exemple|\IfStrEq{}{abc}{true}{false}|
\exemple|\IfStrEq{}{}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfEq}

\verb|\IfEq|\etoile\ARGU{stringA}\ARGU{stringB}\ARGU{true}\ARGU{false}
\smallskip

Tests if the strings \argu{stringA} and \argu{stringB} are equal, \emph{except} if both \argu{stringA} and \argu{stringB} contain numbers in which case the macro tests if these numbers are equal. Runs \argu{true} if so, and \argu{false} otherwise.\smallskip

\begin{Conditions}
	\item The definition of \emph{number} is given with the macro \verb|IfDecimal| (see page~\pageref{ifdecimal}), and thus :
	\item \guill{+} signs are optional;
	\item Decimal separator can be a dot or a comma;
	\item It is possible to evaluate an algebric expression with the $\varepsilon$-\TeX{} primitive \verb|\numexpr|, keeping in mind that it operate on integers only, and that results of divisions are \emph{rounded} and not truncated!
\end{Conditions}

\exemple|\IfEq{a1b2c3}{a1b2c3}{true}{false}|
\exemple|\IfEq{abcdef}{ab}{true}{false}|
\exemple|\IfEq{ab}{abcdef}{true}{false}|
\exemple|\IfEq{12.34}{12,34}{true}{false}|
\exemple|\IfEq{+12.34}{12.340}{true}{false}|
\exemple|\IfEq{10}{+10}{true}{false}|
\exemple|\IfEq{-10}{10}{true}{false}|
\exemple|\IfEq{+0,5}{,5}{true}{false}|
\exemple|\IfEq{1.001}{1.01}{true}{false}|
\exemple|\IfEq{3*4+2}{14}{true}{false}|
\exemple|\IfEq{\number\numexpr3*4+2}{14}{true}{false}|
\exemple|\IfEq{0}{-0.0}{true}{false}|
\exemple|\IfEq{}{}{true}{false}|

\subsubsection{\ttfamily\textbackslash IfStrEqCase}

\begin{minipage}{\textwidth}
	\verb|\IfStrEqCase|\etoile\ARGU{string}\verb|{%|\par
	\qquad\qquad\ARGU{string1}\ARGU{code1}\verb|%|\par
	\qquad\qquad\ARGU{string2}\ARGU{code2}\verb|%|\par
	\qquad\qquad\verb|etc...|\par
	\qquad\qquad\ARGU{stringN}\ARGU{codeN}\verb|}|\arguC{other cases code}
\end{minipage}
\smallskip

Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verb|\IfStrEq| (see above). If the test $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip

\exemple|\IfStrEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
\exemple*|\IfStrEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
\exemple|\IfStrEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]|
\exemple|\IfStrEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]|
\exemple|\IfStrEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]|
\exemple|\IfStrEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|

\subsubsection{\ttfamily\textbackslash IfEqCase}

\begin{minipage}{\textwidth}
	\verb|\IfEqCase|\etoile\ARGU{string}\verb|{%|\par
	\qquad\qquad\ARGU{string1}\ARGU{code1}\verb|%|\par
	\qquad\qquad\ARGU{string2}\ARGU{code2}\verb|%|\par
	\qquad\qquad\verb|etc...|\par
	\qquad\qquad\ARGU{stringN}\ARGU{codeN}\verb|}|\arguC{other cases code}
\end{minipage}
\smallskip

Tests successively if \argu{string} is equal to \argu{string1}, \argu{string2}, etc. Comparison is made with \verb|\IEq| (see above). If the test $i$ is positive (the \argu{string} matches \argu{string\;$i$}), the macro runs \argu{code\;$i$} and ends. If all tests fail, the macro runs the optional \argu{other cases code}, if present.\smallskip

\exemple|\IfEqCase{b}{{a}{AA}{b}{BB}{c}{CC}}|
\exemple*|\IfEqCase{abc}{{a}{AA}{b}{BB}{c}{CC}}|
\exemple|\IfEqCase{c}{{a}{AA}{b}{BB}{c}{CC}}[other]|
\exemple|\IfEqCase{d}{{a}{AA}{b}{BB}{c}{CC}}[other]|
\exemple|\IfEqCase{+3}{{1}{one}{2}{two}{3}{three}}[other]|
\exemple|\IfEqCase{0.5}{{0}{zero}{.5}{half}{1}{one}}[other]|

\subsection{Extraction of substrings}
\subsubsection{\ttfamily\textbackslash StrBefore}

\verb|\StrBefore|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip

The value of the optional argument \argu{number} is 1 by default.\par\smallskip

In \argu{string}, returns what is leftwards the \argu{number}\th occurrence of \argu{stringA}.\medskip

\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, an empty string is returned;
\item If \argu{number}${}<1$ then the macro behaves as if \argu{number}${}=1$;
\item If the occurrence is not found, an empty string is returned.
\end{Conditions}

\exemple*|\StrBefore{xstring}{tri}|
\exemple*|\StrBefore{LaTeX}{e}|
\exemple*|\StrBefore{LaTeX}{p}|
\exemple*|\StrBefore{LaTeX}{L}|
\exemple*|\StrBefore{a bc def }{def}|
\exemple*|\StrBefore{a bc def }{cd}|
\exemple*|\StrBefore[1]{1b2b3}{b}|
\exemple*|\StrBefore[2]{1b2b3}{b}|

\subsubsection{\ttfamily\textbackslash StrBehind}

\verb|\StrBehind|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip

The value of the optional argument \argu{number} is 1 by default.\par\smallskip

In \argu{string}, returns what is rightwards the \argu{number}\th occurrence of \argu{stringA}.\medskip

\begin{Conditions}
\item If \argu{string} or \argu{stringA} is empty, an empty string is returned;
\item If \argu{number}${}<1$ then the macro behaves as if \argu{number}${}=1$;
\item If the occurrence is not found, an empty string is returned.
\end{Conditions}


\exemple*|\StrBehind{xstring}{tri}|
\exemple*|\StrBehind{LaTeX}{e}|
\exemple*|\StrBehind{LaTeX}{p}|
\exemple*|\StrBehind{LaTeX}{X}|
\exemple*|\StrBehind{a bc def }{bc}|
\exemple*|\StrBehind{a bc def }{cd}|
\exemple*|\StrBehind[1]{1b2b3}{b}|
\exemple*|\StrBehind[2]{1b2b3}{b}|
\exemple*|\StrBehind[3]{1b2b3}{b}|

\subsubsection{\ttfamily\textbackslash StrBetween}

\verb|\StrBetween|\etoile\arguCC{number1}{number2}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip

The values of the optional arguments \argu{number1} and \argu{number2} are 1 by default.\par\smallskip

In \argu{string}, returns the substring between\footnote{In a strict sense, i.e. \emph{without} the strings \argu{stringA} and \argu{stringB}} the \argu{number1}\th occurrence of \argu{stringA} and \argu{number2}\th occurrence of \argu{stringB}.\medskip

\begin{Conditions}
\item If the occurrences are not in this order ---~\argu{stringA} \emph{followed by} \argu{stringB}~--- in \argu{string}, an empty string is returned;
\item If one of the 2 occurrences doesn't exist in \argu{string}, an empty string is returned;
\item  If one of the optional arguments \argu{number1} ou \argu{number2} is negative or zero, an empty string is returned.
\end{Conditions}

\exemple*|\StrBetween{xstring}{xs}{ng}|
\exemple*|\StrBetween{xstring}{i}{n}|
\exemple*|\StrBetween{xstring}{a}{tring}|
\exemple*|\StrBetween{a bc def }{a}{d}|
\exemple*|\StrBetween{a bc def }{a }{f}|
\exemple*|\StrBetween{a1b1a2b2a3b3}{a}{b}|
\exemple*|\StrBetween[2,3]{a1b1a2b2a3b3}{a}{b}|
\exemple*|\StrBetween[1,3]{a1b1a2b2a3b3}{a}{b}|
\exemple*|\StrBetween[3,1]{a1b1a2b2a3b3}{a}{b}|
\exemple*|\StrBetween[3,2]{abracadabra}{a}{bra}|

\subsubsection{\ttfamily\textbackslash StrSubstitute}

\verb|\StrSubstitute|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip

The value of the optional argument \argu{number} is 0 by default.\par\smallskip

In \argu{string}, substitute the \argu{number} first occurrences of \argu{stringA} for \argu{stringB}, except if \argu{number}${}=0$ in which case \emph{all} the occurrences are substituted.

\begin{Conditions}
\item If \argu{string} is empty, an empty string is returned;
\item If \argu{stringA} is empty or doesn't exist in \argu{string}, the macro is ineffective;
\item If \argu{number} is greater than the number of occurrences of \argu{stringA}, then all the occurrences are substituted;
\item If \argu{number}${}<0$ the macro behaves as if \argu{number}${}=0$;
\item If \argu{stringB} is empty, the occurrences of \argu{stringA}, if they exist, are deleted.
\end{Conditions}

\exemple|\StrSubstitute{xstring}{i}{a}|
\exemple|\StrSubstitute{abracadabra}{a}{o}|
\exemple|\StrSubstitute{abracadabra}{br}{TeX}|
\exemple|\StrSubstitute{LaTeX}{m}{n}|
\exemple|\StrSubstitute{a bc def }{ }{M}|
\exemple|\StrSubstitute{a bc def }{ab}{AB}|
\exemple|\StrSubstitute[1]{a1a2a3}{a}{B}|
\exemple|\StrSubstitute[2]{a1a2a3}{a}{B}|
\exemple|\StrSubstitute[3]{a1a2a3}{a}{B}|
\exemple|\StrSubstitute[4]{a1a2a3}{a}{B}|

\subsubsection{\ttfamily\textbackslash StrDel}

\verb|\StrDel|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip

The value of the optional argument \argu{number} is 0 by default.\par\smallskip

Delete the \argu{number} first occurrences of \argu{stringA} in \argu{string}, except if \argu{number}${}=0$ in which case \emph{all} the occurrences are deleted.\medskip

\begin{Conditions}
\item If \argu{string} is empty, an empty string is returned;
\item If \argu{stringA} is empty or doesn't exist in \argu{string}, the macro is ineffective;
\item If \argu{number} greater then the number of occurrences of \argu{stringA}, then all the occurrences are deleted;
\item If \argu{number}${}<0$ the macro behaves as if \argu{number}${}=0$;
\end{Conditions}

\exemple|\StrDel{abracadabra}{a}|
\exemple|\StrDel[1]{abracadabra}{a}|
\exemple|\StrDel[4]{abracadabra}{a}|
\exemple|\StrDel[9]{abracadabra}{a}|
\exemple|\StrDel{a bc def }{ }|

\subsubsection{\ttfamily\textbackslash StrSplit}
\verb|\StrSplit|\etoile\ARGU{string}\ARGU{number}\ARGU{csA}\ARGU{csB}
\smallskip

The \argu{string}, is splitted after the character at position \argu{number}. The left part is assigned to the control sequence \argu{csA} and the right part is assigned to \argu{csB}.\par
This macro returns two strings, so it does \emph{not} display anything. Consequently, it does not provide the optional argument in last position.\medskip

\begin{Conditions}
	\item If \argu{number}${}\leqslant0$, \argu{csA} is empty and \argu{csB} is equal to \argu{string};
	\item If \argu{number}${}\geqslant$\argu{lengthString}, \argu{csA} is equal to \argu{string} and \argu{csB} is empty;
	\item If \argu{string} is empty, \argu{csA} and \argu{csB} are empty, whatever be the integer \argu{number}.
\end{Conditions}

\setverbdelim{=}
\exemple=\StrSplit{abcdef}{4}{\aa}{\bb}results: |\aa| and |\bb|=
\exemple=\StrSplit{a b c }{2}{\aa}{\bb}results: |\aa| and |\bb|=
\exemple=\StrSplit{abcdef}{1}{\aa}{\bb}results: |\aa| and |\bb|=
\exemple=\StrSplit{abcdef}{5}{\aa}{\bb}results: |\aa| and |\bb|=
\exemple=\StrSplit{abcdef}{9}{\aa}{\bb}results: |\aa| and |\bb|=
\exemple=\StrSplit{abcdef}{-3}{\aa}{\bb}results: |\aa| and |\bb|=
\setverbdelim{|}

\subsubsection{\ttfamily\textbackslash StrGobbleLeft}

\verb|\StrGobbleLeft|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip

In \argu{string}, delete the \argu{number} first characters on the left.\medskip

\begin{Conditions}
\item If \argu{string} is empty, an empty string is returned;
\item If \argu{number}${}\leqslant0$, no character is deleted;
\item If \argu{number}${}\geqslant{}$\argu{lengthString}, all the characters are deleted.
\end{Conditions}

\exemple*|\StrGobbleLeft{xstring}{2}|
\exemple*|\StrGobbleLeft{xstring}{9}|
\exemple*|\StrGobbleLeft{LaTeX}{4}|
\exemple*|\StrGobbleLeft{LaTeX}{-2}|
\exemple*|\StrGobbleLeft{a bc def }{4}|

\subsubsection{\ttfamily\textbackslash StrLeft}

\verb|\StrLeft|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip

In \argu{string}, returns the \argu{number} first characters on the left.\medskip

\begin{Conditions}
\item If \argu{string} is empty, an empty string is returned;
\item If \argu{number}${}\leqslant0$, no character is returned;
\item If \argu{number}${}\geqslant{}$\argu{lengthString}, all the characters are returned.
\end{Conditions}

\exemple*|\StrLeft{xstring}{2}|
\exemple*|\StrLeft{xstring}{9}|
\exemple*|\StrLeft{LaTeX}{4}|
\exemple*|\StrLeft{LaTeX}{-2}|
\exemple*|\StrLeft{a bc def }{5}|

\subsubsection{\ttfamily\textbackslash StrGobbleRight}

\verb|\StrGobbleRight|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip

In \argu{string}, delete the \argu{number} last characters on the right.\medskip

\exemple*|\StrGobbleRight{xstring}{2}|
\exemple*|\StrGobbleRight{xstring}{9}|
\exemple*|\StrGobbleRight{LaTeX}{4}|
\exemple*|\StrGobbleRight{LaTeX}{-2}|
\exemple*|\StrGobbleRight{a bc def }{4}|

\subsubsection{\ttfamily\textbackslash StrRight}

\verb|\StrRight|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip

In \argu{string}, returns the \argu{number} last characters on the right.\medskip

\exemple*|\StrRight{xstring}{2}|
\exemple*|\StrRight{xstring}{9}|
\exemple*|\StrRight{LaTeX}{4}|
\exemple*|\StrRight{LaTeX}{-2}|
\exemple*|\StrRight{a bc def }{5}|

\subsubsection{\ttfamily\textbackslash StrChar}

\verb|\StrChar|\etoile\ARGU{string}\ARGU{number}\arguC{name}
\smallskip

Returns the character at the position \argu{number} in \argu{string}.\medskip

\begin{Conditions}
\item If \argu{string} is empty, no caracter is returned;
\item If \argu{number}${}\leqslant0$ or if \argu{number}${}>{}$\argu{lengthString}, no character is returned.
\end{Conditions}

\exemple|\StrChar{xstring}{4}|
\exemple*|\StrChar{xstring}{9}|
\exemple*|\StrChar{xstring}{-5}|
\exemple|\StrChar{a bc def }{6}|

\subsubsection{\ttfamily\textbackslash StrMid}

\verb|\StrMid|\etoile\ARGU{string}\ARGU{numberA}\ARGU{numberB}\arguC{name}
\smallskip

In \argu{string}, returns the substring between\footnote{In the broad sense, i.e. that the strings characters of the \guill{border} are returned.} the positions \argu{numberA} and \argu{numberB}.\medskip

\begin{Conditions}
\item If \argu{string} is empty, an empty string is returned;
\item If \argu{numberA}${}>{}$\argu{numberB}, an empty string is returned;
\item If \argu{numberA}${}<1$ and \argu{numberB}${}<1$ an empty string is returned;
\item If \argu{numberA}${}>{}$\argu{lengthString} et \argu{numberB}${}>{}$\argu{lengthString}, an empty string is returned;
\item If \argu{numberA}${}<1$, the macro behaves as if \argu{numberA}${}=1$;
\item If \argu{numberB}${}>{}$\argu{lengthString}, the macro behaves as if \argu{numberB}${}={}$\argu{lengthString}.
\end{Conditions}

\exemple|\StrMid{xstring}{2}{5}|
\exemple|\StrMid{xstring}{-4}{2}|
\exemple*|\StrMid{xstring}{5}{1}|
\exemple|\StrMid{xstring}{6}{15}|
\exemple|\StrMid{xstring}{3}{3}|
\exemple*|\StrMid{a bc def }{2}{7}|

\subsection{Number results}
\subsubsection{\ttfamily\textbackslash StrLen}

\verb|\StrLen|\etoile\ARGU{string}\arguC{name}
\smallskip

Return the length of \argu{string}.

\exemple|\StrLen{xstring}|
\exemple|\StrLen{A}|
\exemple|\StrLen{a bc def }|

\subsubsection{\ttfamily\textbackslash StrCount}

\verb|\StrCount|\etoile\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip

Counts how many times \argu{stringA} is contained in \argu{string}.\par\medskip

\begin{Conditions}
\item If one at least of the arguments \argu{string} or \argu{stringA} is empty, the macro return 0.
\end{Conditions}

\exemple|\StrCount{abracadabra}{a}|
\exemple|\StrCount{abracadabra}{bra}|
\exemple|\StrCount{abracadabra}{tic}|
\exemple|\StrCount{aaaaaa}{aa}|

\subsubsection{\ttfamily\textbackslash StrPosition}

\verb|\StrPosition|\etoile\arguC{number}\ARGU{string}\ARGU{stringA}\arguC{name}
\smallskip

The value of the optional argument \argu{number} is 1 by default.\par\smallskip

In \argu{string}, returns the position of the \argu{number}\th occurrence of \argu{stringA}.\medskip

\begin{Conditions}
\item If \argu{number} is greater than the number of occurrences of \argu{stringA}, then the macro returns 0;
\item If \argu{string} doesn't contain \argu{stringA}, then the macro returns 0.
\end{Conditions}
\medskip

\exemple|\StrPosition{xstring}{ring}|
\exemple|\StrPosition[4]{abracadabra}{a}|
\exemple|\StrPosition[2]{abracadabra}{bra}|
\exemple|\StrPosition[9]{abracadabra}{a}|
\exemple|\StrPosition{abracadabra}{z}|
\exemple|\StrPosition{a bc def }{d}|
\exemple|\StrPosition[3]{aaaaaa}{aa}|

\subsubsection{\ttfamily\textbackslash StrCompare}
\verb|\StrCompare|\etoile\ARGU{stringA}\ARGU{stringB}\arguC{name}
\smallskip

This macro has 2 tolerances: the "normal" tolerance, used bu default, and the "strict" tolerance.
\begin{itemize}
	\item The normal tolerance, activated with \verb|\comparenormal|.\par
	The macro compares characters from left to right in \argu{stringA} and \argu{stringB} until a difference appears or the end of the shortest string is reached. The position of the first difference is returned and if no difference is found, the macro return 0.
	\item The strict tolerance, activated with \verb|\comparestrict|.\par
	The macro compares the 2 strings. If they are equal, it returns 0. If not, the position of the first difference is returned.
\end{itemize}
\medskip

It is possible to save the comparison mode with \verb|\savecomparedmode|, then modify this comparison mode and come back to the situation when it was saved with \verb|\restoreecomparemode|.\medskip

Examples with the normal tolerance:\par\comparenormal
\exemple|\StrCompare{abcd}{abcd}|
\exemple|\StrCompare{abcd}{abc}|
\exemple|\StrCompare{abc}{abcd}|
\exemple|\StrCompare{éùçà}{éùçà}|
\exemple|\StrCompare{a b c}{abc}|
\exemple|\StrCompare{aaa}{baaa}|
\exemple|\StrCompare{abc}{xyz}|
\exemple|\StrCompare{123456}{123457}|
\exemple|\StrCompare{abc}{}|
\medskip

Examples with the strict tolerance:\par\comparestrict
\exemple|\StrCompare{abcd}{abcd}|
\exemple|\StrCompare{abcd}{abc}|
\exemple|\StrCompare{abc}{abcd}|
\exemple|\StrCompare{éùçà}{éùçà}|
\exemple|\StrCompare{a b c}{abc}|
\exemple|\StrCompare{aaa}{baaa}|
\exemple|\StrCompare{abc}{xyz}|
\exemple|\StrCompare{123456}{123457}|
\exemple|\StrCompare{abc}{}|
\comparenormal

\section{Operating modes}
\subsection{Expansion of arguments}
\label{devarg}
\subsubsection{The commands {\ttfamily \textbackslash fullexpandarg}, {\ttfamily \textbackslash expandarg} and {\ttfamily \textbackslash noexpandarg}}
The command \verb|\fullexpandarg| is called by default, so all the arguments are fully expanded (an \verb|\edef| is used) before the the macro is called. In most of the cases, this expansion mode avoids chains of \verb|\expandafter| and allows lighter code.

Of course, the expansion of argument can be canceled to find back the usual behaviour of \TeX{} with the comands \verb|\noexpandarg| or \verb|\normalexpandarg|.\medskip

An other expansion mode can be called with \verb|\expandarg|. In this case, the \textbf{first token} of each argument is expanded \emph{one time} while all other tokens are left unchanged (for the expansion of all tokens one time, you should call the macro \verb|\scancs*|, see page~\pageref{scancs}).\medskip

The commands \verb|\fullexpandarg|, \verb|\noexpandarg|, \verb|\normalexpandarg| and \verb|\expandarg| can be called at any moment in the code; they behave as "switches". They can be locally used in a group.\medskip

It is possible to save the expansion mode with \verb|\saveexpandmode|, then modify this expansion mode and come back to the situation when it was saved with \verb|\restoreexpandmode|.

\subsubsection{Chars allowed in arguments}
First of all, whatever be the current expansion mode, \textbf{tokens with catcode 6 and 14 (usually {\ttfamily\#} and {\ttfamily\%}) are forbidden in all the arguments}\footnote{Maybe, the token {\ttfamily\#} will be allowed in a further version.}.\bigskip

When full expansion mode is activated with \verb|\fullexpandarg|, arguments are expanded with an \verb|\edef| before they are read by the macro. Consequently, are allowed in arguments :
\parindent3em
\begin{itemize}
	\item letters (uppercase or lowercase, accented\footnote{For a reliable operation with accented letters, the \texttt{\string\fontenc} package with option \texttt{[T1]} and \texttt{\string\inputenc} with appropriated option must be loaded} or not), figures, spaces, and any other character with a catcode of 10, 11 ou 12 (punctuation signs, calculation signs, parenthesis, square bracket, etc).;
	\item tokens with catcode 1 to 4, usually : \verb|{|\quad\verb|}|\footnote{Warning : braces \textbf{must} be balanced in arguments !}\quad\verb|$|\quad\verb|&|
	\item tokens with catcode 7 and 8, usually : \verb|^|\quad\verb|_|
	\item any purely expandable control sequence\footnote{i.e. this control sequence can be {\ttfamily\string\edef}ed.} or tokens with catcode 13 (active chars) whose expansion is allowed chars.
\end{itemize}\parindent0pt
\smallskip

On the other hand, some chars\footnote{These chars are obtained with the keys \textsf{AtlGr}${}+{}$letter under GNU/Linux distributions.} like \officialeuro, \textcurrency, ¶, etc. will provoke errors.\medskip

When expansion is not full (\verb|\expandarg| or \verb|\noexpandarg| are active), allowed char in arguments are:\parindent3em
\begin{itemize}
	\item those cited above;
	\item any control sequence or token catocode 13, even undefined;
	\item the special chars (\officialeuro, \textcurrency, ¶, etc.).
\end{itemize}
\parindent0pt

\subsection{Expansion of macros, optional argument}
\label{argumentoptionnel}
The macros of this package are not purely expandable, i.e. they cannot be put in the argument of an \verb|\edef|. Nestling macros is not possible neither, even with \verb|\expandafter|.\medskip

For this reason, all the macros returning a result (i.e. all excepted the tests and \verb|\StrSplit|) have an optional argument in last position. The syntax is \arguC{name}, where \argu{name} is the name of the control sequence that will receive the result of the macro: the assignment is made with an \verb|\edef| which make the result of the macro \argu{name} purely expandable. Of course, if an optional argument is present, the macro does not display anything.\medskip

Thus, this structure not allowed, supposed to assign to \verb|\Result| the 4 chars on the left of \verb|xstring|:\par
\hspace{0.2\linewidth}\verb|\edef\Result{\StrLeft{xstring}{4}}|\par
\qquad is equivalent to :\par
\hspace{0.2\linewidth}\verb|\StrLeft{xstring}{4}[\Result]|\medskip

And this not allowed nested structure, supposed to remove the first and last char of  \verb|xstring|:\par
\hspace{0.2\linewidth}\verb|\StrGobbleLeft{\StrGobbleRight{xstring}{1}}{1}|\par
\qquad can be written like this:\par
\hspace{0.2\linewidth}\verb|\StrGobbleRight{xstring}{1}[\mystring]|\par
\hspace{0.2\linewidth}\verb|\StrGobbleleft{\mystring}{1}|\par

\subsection{How \Xstring reads the arguments?}
\label{developpementarguments}
\subsubsection{Syntax unit by \US}
The macros of \Xstring read their arguments \US par \US. In the \TeX{} code, a \US is either:\parindent3em
\begin{itemize}
	\item a control sequence;
	\item a group, i.e. what is between 2 balanced braces;
	\item a char.
\end{itemize}
\medskip\parindent0pt

Let's see what is a \US with an example. Let's take this argument : "\verb|ab\textbf{xyz}cd|"

It has 6 \USs: "\verb|a|", "\verb|b|", "\verb|\textbf|", "\verb|{xyz}|", "\verb|c|" and "\verb|d|".\medskip

What will happen while \verb|\noexpandarg| is active, we ask \Xstring to find the length of this argument and find its 4\th "char'?\medskip

\begin{minipage}[r]{0.6\linewidth}
\hfill
\begin{boxedverbatim}
	\noexpandarg
	\StrLen{ab\textbf{xyz}cd}\par
	\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
	\meaning\mychar
\end{boxedverbatim}
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\noexpandarg
	\StrLen{ab\textbf{xyz}cd}\par
	\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
	\meaning\mychar
\end{minipage}
\fullexpandarg
\medskip

It is necessary to use \verb|\meaning| to see the real expansion of \verb|\mychar|, and not simply call \verb|\mychar| which make loose informations (braces here). We do not obtain a "char" but a \US, as expected.

\subsubsection{Exploration of groups}
By default, the command \verb|\noexploregroups| is called, so in the main argument, \Xstring does not look into groups, and simply consider them as \US.

For specific uses, it can be necessary to look into groups: \verb|\exploregroups| changes the exploration mode an makes the macros look inside groups.\medskip

What does this exploration mode in the preceding example? \Xstring does not count the group as a single \US but look inside it and counts the \US found inside (\verb|x|, \verb|y| and \verb|z|), and so on if there were several nested groups:\smallskip

\begin{minipage}[r]{0.6\linewidth}
\hfill
\begin{boxedverbatim}
	\noexpandarg
	\exploregroups
	\StrLen{ab\textbf{xyz}cd}\par
	\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
	\meaning\mychar
\end{boxedverbatim}
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\noexpandarg
	\exploregroups
	\StrLen{ab\textbf{xyz}cd}\par
	\StrChar{ab\textbf{xyz}cd}{4}[\mychar]
	\meaning\mychar
\end{minipage}
\fullexpandarg\noexploregroups
\medskip

Exploring the groups can be usefull for counting a substring in a string (\verb|\StrCount|), for the position of a substring in a string (\verb|\StrPosition|) or for tests, but has a severe limitation with macros returning a string: when an argument is cut inside a group, \textbf{the result does not take into account what is outside this group}. This exploration mode must be used knowingly this limitation when calling macros returning a string.\smallskip

Let's see what this means with an example. We want to know what is on the left of the second appearance of \verb|\a| in the argument \verb|\a1{\b1\a2}\a3|. As groups are explored, this appearance is inside this group : \verb|{\b1\a2}|. The result will be \verb|\b1|. Let's check:\smallskip

\begin{minipage}[r]{0.6\linewidth}
\hfill
\begin{boxedverbatim}
	\noexpandarg
	\exploregroups
	\StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
	\meaning\mycs
\end{boxedverbatim}
\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\noexpandarg
	\exploregroups
	\StrBefore[2]{\a1{\b1\a2}\a3}{\a}[\mycs]
	\meaning\mycs
\end{minipage}
\fullexpandarg\noexploregroups
\medskip

Exploring the groups\footnote{The file test of \Xstring has many examples underlining differences between exploration modes.} can change the behaviour of most of the macros of \Xstring, excepted these macros untouched by the exploration mode; their behaviour is the same in any case: \verb|\IfInteger|, \verb|\IfDecimal|, \verb|\IfStrEq|, \verb|\StrEq| et \verb|\StrCompare|.

Moreover, 2 macros run in \verb|\noexploregroups| mode, whatever be the current mode: \verb|\StrBetween| et \verb|\StrMid|.\medskip

It is possible to save the "explore mode" with \verb|\saveexploremode|, then modify this "explore mode" and come back to the situation when it was saved with \verb|\restoreexploremode|.

\subsection{Catcode of arguments, starred macros}
\label{macrosetoilees}
Macros of this package take the catcodes of characters into account. To avoid unexpected behaviour (particulary with tests), you should keep in mind that characters \emph{and their catcodes} are examined.\medskip

For instance, these two arguments:\par\medskip
\hfil\verb|{\string a\string b}|\qquad and\qquad\verb|{ab}|\hfil{}\par\smallskip
do \emph{not} expand into equal strings for xstring! Because of the command \verb|\string|, the first expands into "\verb|ab|" with catcodes 12 while the second have characters with their natural catcodes 11. Catcodes do not match! It is necessary to be aware of this, particulary with \TeX{} commands like \verb|\string| whose expansions are a strings with char catcodes 12 and 10 : \verb|\detokenize|, \verb|\meaning|, \verb|\jobname|, \verb|\fontname|, \verb|\romannumeral|, etc.\medskip

Starred macros do not take catcodes into account. They simply convert their textual arguments into arguments with catcodes 10, 11 and 12, and call the non-starred macros with these modified arguments.\medskip

\textbf{Warning}: the use of a strarred macro has consequences! The arguments are \guill{detokenized}, thus, there is no more control sequences, groups, neither any special char: everything is converted into chars with "harmless" catcodes.\medskip

Here is an example:\par\smallskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\IfStrEq{\string a\string b}{ab}{true}{false}\par
		\IfStrEq*{\string a\string b}{ab}{true}{false}
	\end{boxedverbatim}
	\hspace{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\IfStrEq{\string a\string b}{ab}{true}{false}\par
	\IfStrEq*{\string a\string b}{ab}{true}{false}
\end{minipage}\smallskip

In the example above, after expansion (assumed that  \verb|\fullexpandarg| is active), the first argument contains \verb|{ab}| where, because of \verb|\string|, both chars have catcode 12. The second argument is \verb|{ab}| where both chars have their natural catcode 11. Strings are not equal because of the catcode and the test is negative, if the unstarred version is used.\bigskip

For the macros returning a string, if the starred version is used, the result will be a string in which chars have catcodes 12 and 10 for space. For example, after a "\verb|\StrBefore*{a \b c d}{c}[\mytext]|", the control sequence \verb|\mytext| expands to "\verb|a|${}_{12}$\verb*| |${}_{10}$\verb|\|${}_{12}$\verb|b|${}_{12}$\verb*| |${}_{10}$".

\section{Other macros for assistance in programming}
Though \Xstring is able to read arguments containing \TeX{} or \LaTeX{} code, for some advanced programming needs, it can be insufficient. This chapter presents other macros able to get round some limitations.

\subsection{Assign a verb content, the macro \ttfamily\textbackslash verbtocs}
\label{verbtocs}
The macro \verb|\verbtocs| allow to read the content of a \guill{verb} argument containing special characters: \verb|&|, \verb|~|, \verb|\|, \verb|{|, \verb|}|, \verb|_|, \verb|#|, \verb|$|, \verb|^| et \verb|%|. The catcodes of \guill{normal} characters are left unchanged while special characters take a catcode 12. Then, these characters are assigned to a control sequence. The syntax is:\medskip

\hfill\verb|\verbtocs|\ARGU{name}|\argu{characters}|\hfill{}
\smallskip

\argu{name} is the name of the control sequence receiving, with an \verb|\edef|, the \argu{characters}. \argu{name} thus contains char with catcodes 12 or 10 for space.\medskip

By default, the character delimiting the verb content is \guill{|}. Obviously, this character cannot be both delimiting and being contained into what it delimits. If you need to verbatimize strings containing \guill{|}, you can change at any time the character delimiting the verb content with the macro:\par\medskip
\hfill\verb|\setverbdelim|\ARGU{character}\hfill{}\smallskip

Any \argu{character} with a catcode 11 or 12 can be used\footnote{Several characters can be used, but the syntax of \texttt{\textbackslash verbtocs} becomes less readable ! For this reason, a warning occurs when the argument of \texttt{\textbackslash setverbdelim} contains more than a single character.}. For example, after \verb|\setverbdelim{=}|, a verb argument look like this: \verb|=|\argu{characters}\verb|=|.\medskip

About verb arguments, keep in mind that:
\begin{itemize}
	\item all the characters before |\argu{characters}| are ignored;
	\item inside the verb argument, all the spaces are taken into account, even if they are consecutive.
\end{itemize}
\medskip

Example:\par\medskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\verbtocs{\result}  |a   & b{ c% d$ e \f|
		\result
	\end{boxedverbatim}
	\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\verbtocs{\result}  |a   & b{ c% d$ e \f|
	\result
\end{minipage}

\subsection{Tokenization of a text to a control sequence, the macro \ttfamily\textbackslash tokenize}
The reverse process of what has been seen above is to transform chars into tokens. This is done by the macro:\medskip

\hfill\verb|\tokenize|\ARGU{name}\ARGU{control sequences}\hfill{}
\smallskip

\argu{control sequences} is fully expanded if \verb|\fullexpandarg| has been called, and is not expanded if \verb|\noexpandarg| or \verb|\expandarg| are active. After expansion, the chars are tokenized to tokens and assigned to \argu{name} with a \verb|\def|.\medskip

Example:\par\medskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\verbtocs{\text}|\textbf{a} $\frac{1}{2}$|
		text: \text
		\tokenize{\result}{\text}
		\par
		result: \result
	\end{boxedverbatim}
	\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\raggedright
	\verbtocs{\text}
	  |\textbf{a} $\frac{1}{2}$|
	text: \text
	\tokenize{\result}{\text}
	\par
	result: \result
\end{minipage}
\medskip

Obviously, the control sequence \verb|\result| can be called at the last line since the control sequences it contains are defined.

\subsection{Expansion of a control sequence before verbatimize, the macro \ttfamily\textbackslash scancs}
\label{scancs}
It is possible to expand a control sequence before converting this expansion into text. This is done by the macro:\medskip

\hfill\verb|\scancs|\arguC{number}\ARGU{name}\ARGU{control sequence}\hfill{}
\smallskip

\argu{number}${}=1$ by default and represents the number of times \argu{control sequence} will be expanded before being converted in characters with catcodes 12 (or 10 for spaces). These characters are then assigned to \argu{name}.

If necessary, the depth of expansion can be controlled with the optional argument. If the $n$\th expansion is a control sequence, the control sequence is verbatimized into chars catcodes 12. The following shows all the "depths" of expansion, from 0 to 3:\par\medskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\def\a{1 z 3}
		\def\b{\a}
		\def\c{\b}
		\scancs[0]{\result}{\c}
		expansion 0 : \result\par
		\scancs[1]{\result}{\c}
		expansion 1 : \result\par
		\scancs[2]{\result}{\c}
		expansion 2 : \result\par
		\scancs[3]{\result}{\c}
		expansion 3 : \result
	\end{boxedverbatim}
	\hspace{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\def\a{1 z 3}
	\def\b{\a}
	\def\c{\b}
	\scancs[0]{\result}{\c}
	expansion 0 : \result\par
	\scancs[1]{\result}{\c}
	expansion 1 : \result\par
	\scancs[2]{\result}{\c}
	expansion 2 : \result\par
	\scancs[3]{\result}{\c}
	expansion 3 : \result
\end{minipage}
\medskip

Obviously, it is necessary to ensure that the expansion to the desired depth is possible.\medskip

In normal use, the third argument \argu{control sequence} (or one of its expansions) must contain a single control sequence that will be expanded. If this third argument or one of its expansion contains several control sequences, compilation stops with an error message asking you to use the starred version. This starred version, more difficult to use allows to expand \argu{number} times \emph{all} the control sequences contained in the third argument. It is necessary to keep in mind that if the $n-1$\th expansion contains a group between braces, this group will be expanded at the $n$\th expansion and will loose its braces! It is the same for spaces\footnote{Any call to {\ttfamily\string\scancs*} provoque a warning message warning against this behaviour.}.\medskip

This is an example that shows the deletion of braces during the next expansion:\par\medskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\def\a{1 {2}}
		\def\b{\a \a}
		\scancs*[0]{\result}{{A}\b}
		expansion 0 : \result\par
		\scancs*[1]{\result}{{A}\b}
		expansion 1 : \result\par
		\scancs*[2]{\result}{{A}\b}
		expansion 2 : \result\par
		\scancs*[3]{\result}{{A}\b}
		expansion 3 : \result
	\end{boxedverbatim}
	\hspace{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
		\def\a{1 {2}}
		\def\b{\a \a}
		\scancs*[0]{\result}{{A}\b}
		expansion 0 : \result\par
		\scancs*[1]{\result}{{A}\b}
		expansion 1 : \result\par
		\scancs*[2]{\result}{{A}\b}
		expansion 2 : \result\par
		\scancs*[3]{\result}{{A}\b}
		expansion 3 : \result
\end{minipage}

\subsection{Inside the definition of a macro}
Some difficulties arise inside the definition of a macro, i.e. between braces following a \verb|\def\macro| or a\\\verb|\newcommand\macro|.\medskip

It is forbidden to use the command \verb|\verb| inside the definition of a macro. For the same reasons:\par\medskip
\hfill\textbf{Do not use \texttt{\textbackslash verbtocs} inside the definition of a macro}.\hfill{}\medskip

But then, how to manipulate special characters and "verbatimize" inside the définition of macros ?\bigskip

The \verb|\detokenize| primitive of $\varepsilon$-\TeX can be used but it has limitations:
\begin{itemize}
	\item braces must be balanced;
	\item consecutive spaces make a single space;
	\item the \verb|%| sign is not allowed;
	\item a space is inserted after each control sequence;
	\item \verb|#| signs become  \verb|##|.
\end{itemize}
\medskip

It is better to use \verb|\scancs| and define \emph{outside the definition of the macros} control sequences containing special characters with \verb|\verbtocs|. It is also possible to use \verb|\tokenize| to transform the final result (which is generaly \texte{10,11,12}) into control sequences. See example using these macros at the end of this manual, page~\pageref{exemples}.\medskip

In the following teaching example\footnote{It is possible to make much more simple using \texttt{\textbackslash detokenize}. The macro becomes:\par\texttt{\textbackslash newcommand\textbackslash bracearg[1]\{\textbackslash detokenize\{\{\#1\}\}\}}}, the macro \verb|\bracearg| adds braces to its argument. To make this possible, 2 control sequences \verb|\Ob| and \verb|\Cb| containing "\verb|{|" and "\verb|}|" are defined outside the definition of \verb|\bracearg|, and expanded inside it:\par\medskip
\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\verbtocs{\Ob}|{|
		\verbtocs{\Cb}|}|
		\newcommand\bracearg[1]{%
		    \def\text{#1}%
		    \scancs*{\result}{\Ob\text\Cb}%
		    \result}
		\bracearg{xstring}\par
		\bracearg{\a}
	\end{boxedverbatim}
	\hspace{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\verbtocs{\Ob}|{|
	\verbtocs{\Cb}|}|
	\newcommand\bracearg[1]{%
		\def\text{#1}%
		\scancs*{\result}{\Ob\text\Cb}%
		\result}
	\bracearg{xstring}\par
	\bracearg{\a}
\end{minipage}

\subsection{The macro \ttfamily\textbackslash StrRemoveBraces}
Advanced users may need to remove the braces of an argument.
The macro \verb|\StrRemoveBraces| does this. Its syntax is:\smallskip

\verb|\StrRemoveBraces|\ARGU{stringe}\arguC{name}
\smallskip

This macro is sensitive to exploration mode and will remove \emph{all} the braces with \verb|\exploregroups| while it will remove braces of higher level with \verb|\noexploregroups|.\medskip

\exemple|\noexploregroups|
\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
\exemple|\meaning\mycs|
\exemple|\exploregroups|
\exemple|\StrRemoveBraces{a{b{c}d}e{f}g}[\mycs]|
\exemple|\meaning\mycs|

\subsection{Examples}
\label{exemples}
Here are some very simple examples involving the macros of this package in programming purposes.

\subsubsection{Example 1}
We want to substitute the 2 first \verb|\textit| by \verb|\textbf| in the control sequence \verb|\myCS| which contains \par\smallskip
\hfill\verb|\textit{A}\textit{B}\textit{C}|\hfill{}
\medskip

We expect: \textbf{A}\textbf{B}\textit{C}\medskip

\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\expandarg
		\def\myCS{\textit{A}\textit{B}\textit{C}}
		\def\pattern{\textit}
		\def\replace{\textbf}
		\StrSubstitute[2]{\myCS}{\pattern}{\replace}
	\end{boxedverbatim}
 \hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\expandarg
	\def\myCS{\textit{A}\textit{B}\textit{C}}
	\def\pattern{\textit}
	\def\replace{\textbf}
	\StrSubstitute[2]{\myCS}{\pattern}{\replace}
\end{minipage}\fullexpandarg

\subsubsection{Example 2}
Let's try to write a macro \verb|\tofrac| that transforms an argument of this type \guill{a/b} into \guill{$\frac{a}{b}$}:\par\medskip

First of all, let's cancel the expansion of arguments with \verb|\noexpandarg|, we do not need expansion here. Then, it's easy to cut what is before and behind the first occurrence of \guill{/} (assumed there is a single occurrence) and assign it to \verb|\num| and \verb|\den| and simply call the macro \verb|\frac| :\medskip

\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\noexpandarg
		\newcommand\tofrac[1]{%
		  \StrBefore{#1}{/}[\num]%
		  \StrBehind{#1}{/}[\den]%
		  $\frac{\num}{\den}$%
		}
		\tofrac{15/9}
		\tofrac{u_{n+1}/u_n}
		\tofrac{a^m/a^n}
		\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
	\end{boxedverbatim}
 \hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\noexpandarg
	\newcommand\tofrac[1]{%
		\StrBefore{#1}{/}[\num]%
		\StrBehind{#1}{/}[\den]%
		$\frac{\num}{\den}$}
	\tofrac{15/9}
	\tofrac{u_{n+1}/u_n}
	\tofrac{a^m/a^n}
	\tofrac{x+\sqrt{x}/\sqrt{x^2+x+1}}
\end{minipage}\fullexpandarg

\subsubsection{Example 3}
Let's try to write a macro \verb|\boldafter| which writes in bold the first word that follows the word contained in the expansion of \verb|\word|.\medskip

\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\newcommand\boldafter[2]{%
		  \noexpandarg
		  \StrBehind[1]{#1 }{ #2 }[\word]%
		  \expandarg
		  \StrBefore{\word}{ }[\word]%
		  \StrSubstitute[1]{#1}{\word}{\textbf{\word}}%
		}

		\boldafter{The xstring package is new}{xstring}

		\boldafter{The xstring package is new}{ring}

		\boldafter{The xstring package is new}{is}
	\end{boxedverbatim}
	\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\newcommand\boldafter[2]{%
		\noexpandarg
		\StrBehind[1]{#1 }{ #2 }[\word]%
		\expandarg
		\StrBefore{\word}{ }[\word]%
		\StrSubstitute[1]{#1}{\word}{\textbf{\word}}%
	}

	\boldafter{The xstring package is new}{xstring}

	\boldafter{The xstring package is new}{ring}

	\boldafter{The xstring package is new}{is}
\end{minipage}\fullexpandarg

\subsubsection{Example 4}
A control sequence \verb|\myCS| défined with an \verb|\def| contains control sequences with their possible arguments. How to reverse the order of the 2 first control sequences? For this, a macro \verb|\swaptwofirst| does the job and displays the result. But this time, it is not possible to seek the token \verb|\| (catcode 0) with the macros of \Xstring. This is why the use of \verb|\scancs| is necessary: after the detokenization of the argument, it becomes possible to search the char \verb|\| (catcode 12). After 4 lines, the process made by the macros of \Xstring (\verb|\StrBefore| and \verb|\StrBehind|) is finish, a retokenization is done by \verb|\tokenize| and \verb|\before| and \verb|\after| are swapped at this moment.\medskip

\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\verbtocs{\antislash}|\|
		\newcommand\swaptwofirst[1]{%
		  \fullexpandarg
		  \scancs[0]\chaine{#1}%
		  \StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
		  \StrBehind{\chaine}{\firsttwo}[\others]
		  \StrBefore[2]{\firsttwo}{\antislash}[\before]
		  \StrBehind{\firsttwo}{\before}[\after]%
		  \tokenize\myCS{\after\before\others}%
		  \myCS}

		\swaptwofirst{\underline{A}\textbf{B}\textit{C}}

		\swaptwofirst{\Large\underline{A}\textbf{B}123}
	\end{boxedverbatim}
	\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
	\verbtocs{\antislash}|\|
	\newcommand\swaptwofirst[1]{%
		\fullexpandarg
		\scancs[0]\chaine{#1}%
		\StrBefore[3]{\chaine}{\antislash}[\firsttwo]%
		\StrBehind{\chaine}{\firsttwo}[\others]
		\StrBefore[2]{\firsttwo}{\antislash}[\before]
		\StrBehind{\firsttwo}{\before}[\after]%
		\tokenize\myCS{\after\before\others}%
		\myCS}

	\swaptwofirst{\underline{A}\textbf{B}\textit{C}}

	\swaptwofirst{\Large\underline{A}\textbf{B}123}
\end{minipage}

\subsubsection{Example 5}
A control sequence \verb|\myCS| defined with an \verb|\edef| contains control sequences and "groups" between braces. Let's try to find the $n$\th group, i.e. what is between the $n$\th pair of balanced braces. In this example, \verb|\myCS| contains:\par\medskip
\hfill\verb|\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}|\hfill{}\medskip

\begin{minipage}[r]{0.6\linewidth}
	\hfill
	\begin{boxedverbatim}
		\newcount\occurr
		\newcount\nbgroup
		\newcommand\findgroup[2]{%
		  \scancs[1]{\text}{#2}%
		  \occurr=0
		  \nbgroup=0
		  \def\findthegroup{%
		    \StrBehind{\text}{\Obr}[\remain]%
		    \advance\occurr by 1% next "{"
		    \StrBefore[\the\occurr]{\remain}{\Cbr}[\group]%
		    \StrCount{\group}{\Obr}[\nbA]%
		    \StrCount{\group}{\Cbr}[\nbB]%
		    \ifnum\nbA=\nbB% balanced braces ?
		      \advance\nbgroup by 1
		      \ifnum\nbgroup<#1% not the good group ?
		        \StrBehind{\text}{\group}[\text]%
		        \occurr=0% initialise \text & \occur
		        \findthegroup% do it again
		      \fi
		    \else% unbalanced braces ?
		      % look for next "}"
		      \findthegroup
		    \fi}
		  \findthegroup
		  \group}

		\verbtocs{\Obr}|{|
		\verbtocs{\Cbr}|}|
		\def\myCS{\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}}

		group 1: \findgroup{1}{\myCS}\par
		group 2: \findgroup{2}{\myCS}\par
		group 3: \findgroup{3}{\myCS}
	\end{boxedverbatim}
	\hspace*{0.3cm}
\end{minipage}%
\begin{minipage}[r]{0.3\linewidth}
		\newcount\occurr
		\newcount\nbgroup
		\newcommand\findgroup[2]{%
		  \scancs[1]{\text}{#2}%
		  \occurr=0
		  \nbgroup=0
		  \def\findthegroup{%
		    \StrBehind{\text}{\Obr}[\remain]%
		    \advance\occurr by 1% next "{"
		    \StrBefore[\the\occurr]{\remain}{\Cbr}[\group]%
		    \StrCount{\group}{\Obr}[\nbA]%
		    \StrCount{\group}{\Cbr}[\nbB]%
		    \ifnum\nbA=\nbB% balanced braces ?
		      \advance\nbgroup by 1
		      \ifnum\nbgroup<#1% if it's not the sought group
		        \StrBehind{\text}{\group}[\text]%
		        \occurr=0% initialization of \text & \occur
		        \findthegroup% do it again
		      \fi
		    \else% unbalanced braces ?
		      % look for next "}"
		      \findthegroup
		    \fi}
		  \findthegroup
		  \group}

		\verbtocs{\Obr}|{|
		\verbtocs{\Cbr}|}|
		\def\myCS{\a{1\b{2}}\c{3}\d{4\e{5}\f{6{7}}}}

		groupe 1: \findgroup{1}{\myCS}\par
		groupe 2: \findgroup{2}{\myCS}\par
		groupe 3: \findgroup{3}{\myCS}
\end{minipage}
\medskip

Notice that 2 counters, 2 tests and a double recursion are necessary to find the group: one of each to find which "\verb|}|" delimits the end of the current group, and the others to calculate the number of the group being read.\bigskip\bigskip

\begin{center}
$\star$\par
$\star$\quad$\star$
\end{center}
\bigskip\bigskip

That's all, I hope you will find this package useful !\par
Please, send me an email if you find a bug or if you have any idea of improvement\ldots\medskip

Christian Tellechea
\end{document}