File: chap27_mj.html

package info (click to toggle)
gap 4.15.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 110,212 kB
  • sloc: ansic: 97,261; xml: 48,343; cpp: 13,946; sh: 4,900; perl: 1,650; javascript: 255; makefile: 252; ruby: 9
file content (1315 lines) | stat: -rw-r--r-- 104,680 bytes parent folder | download
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
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
  src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (ref) - Chapter 27: Strings and Characters</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap27"  onload="jscontent()">


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chap12_mj.html">12</a>  <a href="chap13_mj.html">13</a>  <a href="chap14_mj.html">14</a>  <a href="chap15_mj.html">15</a>  <a href="chap16_mj.html">16</a>  <a href="chap17_mj.html">17</a>  <a href="chap18_mj.html">18</a>  <a href="chap19_mj.html">19</a>  <a href="chap20_mj.html">20</a>  <a href="chap21_mj.html">21</a>  <a href="chap22_mj.html">22</a>  <a href="chap23_mj.html">23</a>  <a href="chap24_mj.html">24</a>  <a href="chap25_mj.html">25</a>  <a href="chap26_mj.html">26</a>  <a href="chap27_mj.html">27</a>  <a href="chap28_mj.html">28</a>  <a href="chap29_mj.html">29</a>  <a href="chap30_mj.html">30</a>  <a href="chap31_mj.html">31</a>  <a href="chap32_mj.html">32</a>  <a href="chap33_mj.html">33</a>  <a href="chap34_mj.html">34</a>  <a href="chap35_mj.html">35</a>  <a href="chap36_mj.html">36</a>  <a href="chap37_mj.html">37</a>  <a href="chap38_mj.html">38</a>  <a href="chap39_mj.html">39</a>  <a href="chap40_mj.html">40</a>  <a href="chap41_mj.html">41</a>  <a href="chap42_mj.html">42</a>  <a href="chap43_mj.html">43</a>  <a href="chap44_mj.html">44</a>  <a href="chap45_mj.html">45</a>  <a href="chap46_mj.html">46</a>  <a href="chap47_mj.html">47</a>  <a href="chap48_mj.html">48</a>  <a href="chap49_mj.html">49</a>  <a href="chap50_mj.html">50</a>  <a href="chap51_mj.html">51</a>  <a href="chap52_mj.html">52</a>  <a href="chap53_mj.html">53</a>  <a href="chap54_mj.html">54</a>  <a href="chap55_mj.html">55</a>  <a href="chap56_mj.html">56</a>  <a href="chap57_mj.html">57</a>  <a href="chap58_mj.html">58</a>  <a href="chap59_mj.html">59</a>  <a href="chap60_mj.html">60</a>  <a href="chap61_mj.html">61</a>  <a href="chap62_mj.html">62</a>  <a href="chap63_mj.html">63</a>  <a href="chap64_mj.html">64</a>  <a href="chap65_mj.html">65</a>  <a href="chap66_mj.html">66</a>  <a href="chap67_mj.html">67</a>  <a href="chap68_mj.html">68</a>  <a href="chap69_mj.html">69</a>  <a href="chap70_mj.html">70</a>  <a href="chap71_mj.html">71</a>  <a href="chap72_mj.html">72</a>  <a href="chap73_mj.html">73</a>  <a href="chap74_mj.html">74</a>  <a href="chap75_mj.html">75</a>  <a href="chap76_mj.html">76</a>  <a href="chap77_mj.html">77</a>  <a href="chap78_mj.html">78</a>  <a href="chap79_mj.html">79</a>  <a href="chap80_mj.html">80</a>  <a href="chap81_mj.html">81</a>  <a href="chap82_mj.html">82</a>  <a href="chap83_mj.html">83</a>  <a href="chap84_mj.html">84</a>  <a href="chap85_mj.html">85</a>  <a href="chap86_mj.html">86</a>  <a href="chap87_mj.html">87</a>  <a href="chapBib_mj.html">Bib</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<div class="chlinkprevnexttop">&nbsp;<a href="chap0_mj.html">[Top of Book]</a>&nbsp;  <a href="chap0_mj.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap26_mj.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap28_mj.html">[Next Chapter]</a>&nbsp;  </div>

<p id="mathjaxlink" class="pcenter"><a href="chap27.html">[MathJax off]</a></p>
<p><a id="X7D28329B7EDB8F47" name="X7D28329B7EDB8F47"></a></p>
<div class="ChapSects"><a href="chap27_mj.html#X7D28329B7EDB8F47">27 <span class="Heading">Strings and Characters</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X7A90690B78260194">27.1 <span class="Heading">IsChar and IsString</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X80CFAE128560E064">27.1-1 IsChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X78723B5D795A3B6D">27.1-2 IsString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7B1B45C587A72F96">27.1-3 <span class="Heading">Strings As Lists</span></a>
</span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7EA6CA7486D7E9DD">27.1-4 <span class="Heading">Printing Strings</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X82E5F5AB818F32DB">27.2 <span class="Heading">Special Characters</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X7E70384E7D0B7083">27.3 <span class="Heading">Triple Quoted Strings</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X82AEC07487C45ECD">27.4 <span class="Heading">Internally Represented Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7A17EDF8785C9F58">27.4-1 IsStringRep</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7CE2415F7FEC5809">27.4-2 ConvertToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7FFC464683CC8023">27.4-3 CopyToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7D944D507CBB24CD">27.4-4 IsEmptyString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X836078DC829A8221">27.4-5 EmptyString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7DA671FC7F490C16">27.4-6 CharsFamily</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X82F980A17FE84AA4">27.5 <span class="Heading">Recognizing Characters</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X78566FD57B95ECBE">27.5-1 IsDigitChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X854114A97BAFEAEA">27.5-2 IsLowerAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87B1A13D81353AD8">27.5-3 IsUpperAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X84634DF67A431D26">27.5-4 IsAlphaChar</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X8127954B79B8A0DA">27.6 <span class="Heading">Comparisons of Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X79538F138286739A"><code>27.6-1 \=</code></a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8129E3A785F60093"><code>27.6-2 \&lt;</code></a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X7E72717A82A309F5">27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X792FB3A1849FD739">27.7-1 DisplayString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8482132779EA7A23">27.7-2 DEFAULTDISPLAYSTRING</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7803FBCA79DB5529">27.7-3 ViewString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7BBDF9D383595425">27.7-4 DEFAULTVIEWSTRING</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7B3CC87285DEC23D">27.7-5 PrintString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X81FB5BE27903EC32">27.7-6 String</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X86AACCE987F74FA5">27.7-7 StripLineBreakCharacters</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X865FBB7E788017DD">27.7-8 HexStringInt</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7BB1059185AB4F84">27.7-9 StringPP</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X79C8280A853D8FA9">27.7-10 WordAlp</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X798A0F35852ABDAD">27.7-11 LowercaseString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87A2F2557DE7EE08">27.7-12 LowercaseChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7E7E5F5B7FED56A0">27.7-13 UppercaseString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X81E0AEE687200505">27.7-14 UppercaseChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X86E897D486DCFEAB">27.7-15 SplitString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X864F0A9078D4DE0E">27.7-16 ReplacedString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X806379367A53D171">27.7-17 NormalizeWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8685DE9386E57771">27.7-18 NormalizedWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X86EBB6EB829723E4">27.7-19 RemoveCharacters</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X84624FEB825EC4B5">27.7-20 JoinStringsWithSeparator</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X79F8FFC5876D854A">27.7-21 Chomp</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X855820848179CC28">27.7-22 StartsWith</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8235AD797868E872">27.7-23 StringFormatted</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7848A9D878FD59BB">27.7-24 NumbersString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X787EAB117816578E">27.7-25 StringNumbers</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X82975B6480932683">27.7-26 StringOfMemoryAmount</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X844BDC8578A3B508">27.8 <span class="Heading">Character Conversion</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X826D95D680F87D23">27.8-1 IntChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87B6C1AF7E4A6639">27.8-2 CharInt</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8159CE81798DDA76">27.8-3 SIntChar</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X78E6611A829DDA3E">27.8-4 CharSInt</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X78D9BD857F890C0A">27.9 <span class="Heading">Operations to Evaluate Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7B6D118184F692A0">27.9-1 Int</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87AD395584294FF2">27.9-2 Rat</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X796D366B7DDEFF67">27.9-3 IntHexString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7C0C29C87CBA97B7">27.9-4 Ordinal</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7DE4CCD285440659">27.9-5 EvalString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7D4B9D7A7995C55D">27.9-6 CrcString</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7873D1F28779B490">27.9-7 HexSHA256</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X83FF17E782E6FFF3">27.9-8 Pluralize</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X78F20AA1804D524F">27.10 <span class="Heading">Calendar Arithmetic</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87BA46787FF000E8">27.10-1 DaysInYear</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X8791B0B386D59ADB">27.10-2 DaysInMonth</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7CED84C07CD5E2CF">27.10-3 DMYDay</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7A79DEE07A41B8EF">27.10-4 DayDMY</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X87D03FC0809DB6EC">27.10-5 WeekDay</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X7C74C33784CDED6C">27.10-6 StringDate</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X84A6A2637FB35A32">27.10-7 HMSMSec</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X879461D77C81100B">27.10-8 SecHMSM</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X802469C47F886A59">27.10-9 StringTime</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X870A71D47B0E936E">27.10-10 SecondsDMYhms</a></span>
<span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27_mj.html#X78AF8EA887532B5B">27.10-11 DMYhmsSeconds</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27_mj.html#X78024C8087F3E07F">27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></a>
</span>
</div>
</div>

<h3>27 <span class="Heading">Strings and Characters</span></h3>

<p><a id="X7A90690B78260194" name="X7A90690B78260194"></a></p>

<h4>27.1 <span class="Heading">IsChar and IsString</span></h4>

<p><a id="X80CFAE128560E064" name="X80CFAE128560E064"></a></p>

<h5>27.1-1 IsChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsChar</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsCharCollection</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;category&nbsp;)</td></tr></table></div>
<p>A <em>character</em> is simply an object in <strong class="pkg">GAP</strong> that represents an arbitrary character from the character set of the operating system. Character literals can be entered in <strong class="pkg">GAP</strong> by enclosing the character in <em>singlequotes</em> <code class="code">'</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">x:= 'a';  IsChar( x );</span>
'a'
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">'*';</span>
'*'
</pre></div>

<p><a id="X78723B5D795A3B6D" name="X78723B5D795A3B6D"></a></p>

<h5>27.1-2 IsString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsString</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;filter&nbsp;)</td></tr></table></div>
<p>A <em>string</em> is a dense list (seeĀ <code class="func">IsList</code> (<a href="chap21_mj.html#X7C4CC4EA8299701E"><span class="RefLink">21.1-1</span></a>), <code class="func">IsDenseList</code> (<a href="chap21_mj.html#X870AA9D8798C93DD"><span class="RefLink">21.1-2</span></a>)) of characters (seeĀ <code class="func">IsChar</code> (<a href="chap27_mj.html#X80CFAE128560E064"><span class="RefLink">27.1-1</span></a>)); thus strings are always homogeneous (seeĀ <code class="func">IsHomogeneousList</code> (<a href="chap21_mj.html#X7C71596C82B6EF35"><span class="RefLink">21.1-3</span></a>)).</p>

<p>A string literal can either be entered as the list of characters or by writing the characters between <em>doublequotes</em> <code class="code">"</code>. <strong class="pkg">GAP</strong> will always output strings in the latter format. However, the input via the double quote syntax enables <strong class="pkg">GAP</strong> to store the string in an efficient compact internal representation. See <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>) below for more details.</p>

<p>Each character, in particular those which cannot be typed directly from the keyboard, can also be typed in three digit octal notation, or two digit hexadecimal notation. And for some special characters (like the newline character) there is a further possibility to type them, see section <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1 := ['H','e','l','l','o',' ','w','o','r','l','d','.'];</span>
"Hello world."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( s1 );</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2 := "Hello world.";</span>
"Hello world."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1 = s2;</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s3 := "";  # the empty string</span>
""
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s3 = [];</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [] );</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( "123" );  IsString( 123 );</span>
true
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', '3' ] );</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', , '4' ] );  # strings must be dense</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', 3 ] );  # strings must only contain characters</span>
false
</pre></div>

<p><a id="X7B1B45C587A72F96" name="X7B1B45C587A72F96"></a></p>

<h5>27.1-3 <span class="Heading">Strings As Lists</span></h5>

<p>Note that a string is just a special case of a list. So everything that is possible for lists (seeĀ <a href="chap21_mj.html#X7B256AE5780F140A"><span class="RefLink">21</span></a>) is also possible for strings. Thus you can access the characters in such a string (seeĀ <a href="chap21_mj.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>), test for membership (seeĀ <a href="chap30_mj.html#X82D39CF980FDBFFA"><span class="RefLink">30.6</span></a>), ask for the length, concatenate strings (seeĀ <code class="func">Concatenation</code> (<a href="chap21_mj.html#X840C55A77D1BB2E1"><span class="RefLink">21.20-1</span></a>)), form substrings etc. You can even assign to a mutable string (seeĀ <a href="chap21_mj.html#X8611EF768210625B"><span class="RefLink">21.4</span></a>). Of course unless you assign a character in such a way that the list stays dense, the resulting list will no longer be a string.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Length( s2 );</span>
12
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2[2];</span>
'e'
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">'a' in s2;</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2[2] := 'a';;  s2;</span>
"Hallo world."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1{ [1..4] };</span>
"Hell"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Concatenation( s1{ [ 1 .. 6 ] }, s1{ [ 1 .. 4 ] } );</span>
"Hello Hell"
</pre></div>

<p><a id="X7EA6CA7486D7E9DD" name="X7EA6CA7486D7E9DD"></a></p>

<h5>27.1-4 <span class="Heading">Printing Strings</span></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ViewObj</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;method&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrintObj</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;method&nbsp;)</td></tr></table></div>
<p>If a string is displayed by <code class="func">View</code> (<a href="chap6_mj.html#X851902C583B84CDC"><span class="RefLink">6.3-3</span></a>), for example as result of an evaluation (seeĀ <a href="chap6_mj.html#X81667F568237B232"><span class="RefLink">6.1</span></a>), or by <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>), it is displayed with enclosing doublequotes. (But note that there is an ambiguity for the empty string which is also an empty list of arbitrary <strong class="pkg">GAP</strong> objects; it is only printed like a string if it was input as empty string or converted to a string with <code class="func">ConvertToStringRep</code> (<a href="chap27_mj.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>).) The output of <code class="func">PrintObj</code> can be read back into <strong class="pkg">GAP</strong>.</p>

<p>Strings behave differently from other <strong class="pkg">GAP</strong> objects with respect to <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>). These commands <em>interpret</em> a string in the sense that they essentially send the characters of the string directly to the output stream/file. (But depending on the type of the stream and the presence of some special characters used as hints for line breaks there may be sent some additional newline (or backslash and newline) characters.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s4:= "abc\"def\nghi";;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">View( s4 );  Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ViewObj( s4 );  Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintObj( s4 );  Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s4 );  Print( "\n" );</span>
abc"def
ghi
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "German uses strange characters: äöüß\n";</span>
"German uses strange characters: äöüß\n"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(s);</span>
German uses strange characters: äöüß
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintObj(s);  Print( "\n" );</span>
"German uses strange characters: \303\244\303\266\303\274\303\237\n"
</pre></div>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "\007";</span>
"\007"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(s); # rings bell in many terminals</span>
</pre></div>

<p>Note that only those line breaks are printed by <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>) that are contained in the string (<code class="code">\n</code> characters, seeĀ <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>), as is shown in the example below.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1;</span>
"Hello world."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s1 );</span>
Hello world.gap&gt; Print( s1, "\n" );
Hello world.
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s1, "\nnext line\n" );</span>
Hello world.
next line
</pre></div>

<p><a id="X82E5F5AB818F32DB" name="X82E5F5AB818F32DB"></a></p>

<h4>27.2 <span class="Heading">Special Characters</span></h4>

<p>There are a number of <em>special character sequences</em> that can be used between the singlequotes of a character literal or between the doublequotes of a string literal to specify characters. They consist of a backslash <code class="code">\</code> followed by a second character indicating the type of special character sequence, and possibly more characters. The following special character sequences are currently defined. For any other sequence starting with a backslash, the backslash is ignored.</p>


<dl>
<dt><strong class="Mark">


<code class="code">\n</code></strong></dt>
<dd><p><em>newline character</em>. This is the character that, at least on UNIX systems, separates lines in a text file. Printing of this character in a string has the effect of moving the cursor down one line and back to the beginning of the line.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\"</code></strong></dt>
<dd><p><em>doublequote character</em>. Inside a string a doublequote must be escaped by the backslash, because it is otherwise interpreted as end of the string.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\'</code></strong></dt>
<dd><p><em>singlequote character</em>. Inside a character a singlequote must escaped by the backslash, because it is otherwise interpreted as end of the character.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\\</code></strong></dt>
<dd><p><em>backslash character</em>. Inside a string a backslash must be escaped by another backslash, because it is otherwise interpreted as first character of an escape sequence.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\b</code></strong></dt>
<dd><p><em>backspace character</em>. Printing this character should have the effect of moving the cursor back one character. Whether it works or not is system dependent and should not be relied upon.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\r</code></strong></dt>
<dd><p><em>carriage return character</em>. Printing this character should have the effect of moving the cursor back to the beginning of the same line. Whether this works or not is again system dependent.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\c</code></strong></dt>
<dd><p><em>flush character</em>. This character is not printed. Its purpose is to flush the output queue. Usually <strong class="pkg">GAP</strong> waits until it sees a <code class="code">newline</code> before it prints a string. If you want to display a string that does not include this character use <code class="code">\c</code>.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\XYZ</code></strong></dt>
<dd><p>with <code class="code">X</code>, <code class="code">Y</code>, <code class="code">Z</code> three octal digits, that is one of <code class="code">"01234567"</code>. This is translated to the character corresponding to the number <code class="code">X * 64 + Y * 8 + Z modulo 256</code>. This can be used to specify and store arbitrary binary data as a string in <strong class="pkg">GAP</strong>.</p>

</dd>
<dt><strong class="Mark">


<code class="code">\0xYZ</code></strong></dt>
<dd><p>with <code class="code">Y</code>, and <code class="code">Z</code> hexadecimal digits, that is one of <code class="code">"0123456789ABCDEFabcdef"</code>, where <code class="code">a</code> to <code class="code">f</code> and <code class="code">A</code> to <code class="code">F</code> are interpreted as the numbers <code class="code">10</code> to <code class="code">15</code>. This is translated to the character corresponding to the number <code class="code">Y*16 + Z</code>.</p>

</dd>
<dt><strong class="Mark">

other</strong></dt>
<dd><p>For any other character the backslash is ignored.</p>

</dd>
</dl>
<p>Again, if the line is displayed as result of an evaluation, those escape sequences are displayed in the same way that they are input.</p>

<p>Only <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>) send the characters directly to the output stream.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"This is one line.\nThis is another line.\n";</span>
"This is one line.\nThis is another line.\n"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( last );</span>
This is one line.
This is another line.
</pre></div>

<p>Note in particular that it is not allowed to enclose a <var class="Arg">newline</var> inside the string. You can use the special character sequence <code class="code">\n</code> to write strings that include <var class="Arg">newline</var> characters. If, however, an input string is too long to fit on a single line it is possible to <em>continue</em> it over several lines. In this case the last character of each input line, except the last line must be a backslash. Both backslash and <var class="Arg">newline</var> are thrown away by <strong class="pkg">GAP</strong> while reading the string. Note that the same continuation mechanism is available for identifiers and integers, seeĀ <a href="chap6_mj.html#X866092F281910B74"><span class="RefLink">6.2</span></a>. The rules on escaping are ignored in a triple quoted string, see <a href="chap27_mj.html#X7E70384E7D0B7083"><span class="RefLink">27.3</span></a></p>

<p><a id="X7E70384E7D0B7083" name="X7E70384E7D0B7083"></a></p>

<h4>27.3 <span class="Heading">Triple Quoted Strings</span></h4>

<p>Another method of entering strings in GAP is triple quoted strings. Triple quoted strings ignore the rules on escaping given in <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>. Triple quoted strings begin an end with three doublequotes. Inside the triple quotes no escaping is done, and the string continues, including newlines, until three doublequotes are found.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"""Print("\n")""";</span>
"Print(\"\\n\")"
</pre></div>

<p>Triple quoted strings are represented internally identically to all other strings, they only provide an alternative method of giving strings to GAP. Triple quoted strings still follow GAP's line editing rules (<a href="chap6_mj.html#X866092F281910B74"><span class="RefLink">6.2</span></a>), which state that in normal line editing mode, lines starting <code class="code">gap&gt; </code>, <code class="code">&gt; </code> or <code class="code">brk&gt; </code> will have this beginning part removed.</p>

<p><a id="X82AEC07487C45ECD" name="X82AEC07487C45ECD"></a></p>

<h4>27.4 <span class="Heading">Internally Represented Strings</span></h4>

<p><a id="X7A17EDF8785C9F58" name="X7A17EDF8785C9F58"></a></p>

<h5>27.4-1 IsStringRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;representation&nbsp;)</td></tr></table></div>
<p><code class="func">IsStringRep</code> is a special (internal) representation of dense lists of characters. Dense lists of characters can be converted into this representation using <code class="func">ConvertToStringRep</code> (<a href="chap27_mj.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>). Note that calling <code class="func">IsString</code> (<a href="chap27_mj.html#X78723B5D795A3B6D"><span class="RefLink">27.1-2</span></a>) does <em>not</em> change the representation.</p>

<p><a id="X7CE2415F7FEC5809" name="X7CE2415F7FEC5809"></a></p>

<h5>27.4-2 ConvertToStringRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ConvertToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>If <var class="Arg">obj</var> is a dense internally represented list of characters then <code class="func">ConvertToStringRep</code> changes the representation to <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). This is useful in particular for converting the empty list <code class="code">[]</code>, which usually is in <code class="func">IsPlistRep</code> (<a href="chap21_mj.html#X87BA4EBF80F16B72"><span class="RefLink">21.24-2</span></a>), to <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). If <var class="Arg">obj</var> is not a string then <code class="func">ConvertToStringRep</code> signals an error.</p>

<p><a id="X7FFC464683CC8023" name="X7FFC464683CC8023"></a></p>

<h5>27.4-3 CopyToStringRep</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CopyToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>If <var class="Arg">obj</var> is a dense internally represented list of characters then <code class="func">CopyToStringRep</code> copies <var class="Arg">obj</var> to a new object with representation <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). If <var class="Arg">obj</var> is not a string then <code class="func">CopyToStringRep</code> signals an error.</p>

<p><a id="X7D944D507CBB24CD" name="X7D944D507CBB24CD"></a></p>

<h5>27.4-4 IsEmptyString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsEmptyString</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p><code class="func">IsEmptyString</code> returns <code class="keyw">true</code> if <var class="Arg">str</var> is the empty string in the representation <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>), and <code class="keyw">false</code> otherwise. Note that the empty list <code class="code">[]</code> and the empty string <code class="code">""</code> have the same type, the recommended way to distinguish them is via <code class="func">IsEmptyString</code>. For formatted printing, this distinction is sometimes necessary.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l:= [];;  IsString( l );  IsEmptyString( l );  IsEmpty( l );</span>
true
false
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l;  ConvertToStringRep( l );  l;</span>
[  ]
""
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsEmptyString( l );  IsEmptyString( "" );  IsEmptyString( "abc" );</span>
true
true
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ll:= [ 'a', 'b' ];  IsStringRep( ll );  ConvertToStringRep( ll );</span>
"ab"
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ll;  IsStringRep( ll );</span>
"ab"
true
</pre></div>

<p><a id="X836078DC829A8221" name="X836078DC829A8221"></a></p>

<h5>27.4-5 EmptyString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; EmptyString</code>( <var class="Arg">len</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns: a string</p>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ShrinkAllocationString</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns: nothing</p>

<p>The function <code class="func">EmptyString</code> returns an empty string in internal representation which has enough memory allocated for <var class="Arg">len</var> characters. This can be useful for creating and filling a string with a known number of entries.</p>

<p>The function <code class="func">ShrinkAllocationString</code> gives back to <strong class="pkg">GAP</strong>s memory manager the physical memory which is allocated for the string <var class="Arg">str</var> in internal representation but not needed by its current number of characters.</p>

<p>These functions are intended for saving some of <strong class="pkg">GAP</strong>s memory in certain situations, see the explanations and the example for the analogous functions <code class="func">EmptyPlist</code> (<a href="chap21_mj.html#X78BF67A5802E93AD"><span class="RefLink">21.9-1</span></a>) and <code class="func">ShrinkAllocationPlist</code> (<a href="chap21_mj.html#X78BF67A5802E93AD"><span class="RefLink">21.9-1</span></a>) for plain lists.</p>

<p><a id="X7DA671FC7F490C16" name="X7DA671FC7F490C16"></a></p>

<h5>27.4-6 CharsFamily</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CharsFamily</code></td><td class="tdright">(&nbsp;family&nbsp;)</td></tr></table></div>
<p>Each character lies in the family <code class="func">CharsFamily</code>, each nonempty string lies in the collections family of this family. Note the subtle differences between the empty list <code class="code">[]</code> and the empty string <code class="code">""</code> when both are printed.</p>

<p><a id="X82F980A17FE84AA4" name="X82F980A17FE84AA4"></a></p>

<h4>27.5 <span class="Heading">Recognizing Characters</span></h4>

<p><a id="X78566FD57B95ECBE" name="X78566FD57B95ECBE"></a></p>

<h5>27.5-1 IsDigitChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsDigitChar</code>( <var class="Arg">c</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is a digit, i.e., occurs in the string <code class="code">"0123456789"</code>.</p>

<p><a id="X854114A97BAFEAEA" name="X854114A97BAFEAEA"></a></p>

<h5>27.5-2 IsLowerAlphaChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsLowerAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is a lowercase alphabet letter, i.e., occurs in the string <code class="code">"abcdefghijklmnopqrstuvwxyz"</code>.</p>

<p><a id="X87B1A13D81353AD8" name="X87B1A13D81353AD8"></a></p>

<h5>27.5-3 IsUpperAlphaChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsUpperAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is an uppercase alphabet letter, i.e., occurs in the string <code class="code">"ABCDEFGHIJKLMNOPQRSTUVWXYZ"</code>.</p>

<p><a id="X84634DF67A431D26" name="X84634DF67A431D26"></a></p>

<h5>27.5-4 IsAlphaChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IsAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is either a lowercase or an uppercase alphabet letter.</p>

<p><a id="X8127954B79B8A0DA" name="X8127954B79B8A0DA"></a></p>

<h4>27.6 <span class="Heading">Comparisons of Strings</span></h4>

<p><a id="X79538F138286739A" name="X79538F138286739A"></a></p>

<h5><code>27.6-1 \=</code></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; \=</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">(&nbsp;method&nbsp;)</td></tr></table></div>
<p>The equality operator <code class="code">=</code> returns <code class="keyw">true</code> if the two strings <var class="Arg">string1</var> and <var class="Arg">string2</var> are equal and <code class="keyw">false</code> otherwise. The inequality operator <code class="code">&lt;&gt;</code> returns <code class="keyw">true</code> if the two strings <var class="Arg">string1</var> and <var class="Arg">string2</var> are not equal and <code class="keyw">false</code> otherwise.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world.\n" = "Hello world.\n";</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello World.\n" = "Hello world.\n"; # comparison is case sensitive</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world." = "Hello world.\n";  # first string has no &lt;newline&gt;</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Goodbye world.\n" = "Hello world.\n";</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">[ 'a', 'b' ] = "ab";</span>
true
</pre></div>

<p><a id="X8129E3A785F60093" name="X8129E3A785F60093"></a></p>

<h5><code>27.6-2 \&lt;</code></h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; \&lt;</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">(&nbsp;method&nbsp;)</td></tr></table></div>
<p>The ordering of strings is lexicographically according to the order implied by the underlying, system dependent, character set.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world.\n" &lt; "Hello world.\n";  # the strings are equal</span>
false
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># in ASCII capitals range before small letters:</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello World." &lt; "Hello world.";</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world." &lt; "Hello world.\n";  # prefixes are always smaller</span>
true
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># G comes before H, in ASCII at least:</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Goodbye world.\n" &lt; "Hello world.\n";</span>
true
</pre></div>

<p>Strings can be compared via <code class="code">&lt;</code> with certain <strong class="pkg">GAP</strong> objects that are not strings, seeĀ <a href="chap4_mj.html#X7A274A1F8553B7E6"><span class="RefLink">4.13</span></a> for the details.</p>

<p><a id="X7E72717A82A309F5" name="X7E72717A82A309F5"></a></p>

<h4>27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></h4>

<p>For the possibility to print <strong class="pkg">GAP</strong> objects to strings, seeĀ <a href="chap10_mj.html#X8028E1D87CE2F059"><span class="RefLink">10.7</span></a>.</p>

<p><a id="X792FB3A1849FD739" name="X792FB3A1849FD739"></a></p>

<h5>27.7-1 DisplayString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DisplayString</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
<p>Returns a string which could be used to display the object <var class="Arg">obj</var> in a nice, formatted way which is easy to read (but might be difficult for machines to understand). The actual format used for this depends on the type of <var class="Arg">obj</var>. Each method should include a newline character as last character. Note that no method for <code class="func">DisplayString</code> may delegate to any of the operations <code class="func">Display</code> (<a href="chap6_mj.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) or <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to avoid circular delegations.</p>

<p><a id="X8482132779EA7A23" name="X8482132779EA7A23"></a></p>

<h5>27.7-2 DEFAULTDISPLAYSTRING</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DEFAULTDISPLAYSTRING</code></td><td class="tdright">(&nbsp;global variable&nbsp;)</td></tr></table></div>
<p>This is the default value for <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>).</p>

<p><a id="X7803FBCA79DB5529" name="X7803FBCA79DB5529"></a></p>

<h5>27.7-3 ViewString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ViewString</code>( <var class="Arg">obj</var> )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
<p><code class="func">ViewString</code> returns a string which would be displayed by <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) for an object. Note that no method for <code class="func">ViewString</code> may delegate to any of the operations <code class="func">Display</code> (<a href="chap6_mj.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>), <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>) or <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to avoid circular delegations.</p>

<p><a id="X7BBDF9D383595425" name="X7BBDF9D383595425"></a></p>

<h5>27.7-4 DEFAULTVIEWSTRING</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DEFAULTVIEWSTRING</code></td><td class="tdright">(&nbsp;global variable&nbsp;)</td></tr></table></div>
<p>This is the default value for <code class="func">ViewString</code> (<a href="chap27_mj.html#X7803FBCA79DB5529"><span class="RefLink">27.7-3</span></a>).</p>

<p><a id="X7B3CC87285DEC23D" name="X7B3CC87285DEC23D"></a></p>

<h5>27.7-5 PrintString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrintString</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
<p><code class="func">PrintString</code> returns a representation of <var class="Arg">obj</var>, which may be an object of arbitrary type, as a string. This string should approximate as closely as possible the character sequence you see if you print <var class="Arg">obj</var> using <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>).</p>

<p>If <var class="Arg">length</var> is given it must be an integer. The absolute value gives the minimal length of the result. If the string representation of <var class="Arg">obj</var> takes less than that many characters it is filled with blanks. If <var class="Arg">length</var> is positive it is filled on the left, if <var class="Arg">length</var> is negative it is filled on the right.</p>

<p>In the two argument case, the string returned is a new mutable string (in particular not a part of any other object); it can be modified safely, and <code class="func">MakeImmutable</code> (<a href="chap12_mj.html#X80CE136D804097C7"><span class="RefLink">12.6-4</span></a>) may be safely applied to it.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintString(123);PrintString([1,2,3]);</span>
"123"
"[ 1, 2, 3 ]"
</pre></div>

<p><code class="func">PrintString</code> is entitled to put in additional control characters <code class="code">\&lt;</code> (ASCII 1) and <code class="code">\&gt;</code> (ASCII 2) that allow proper line breaks. See <code class="func">StripLineBreakCharacters</code> (<a href="chap27_mj.html#X86AACCE987F74FA5"><span class="RefLink">27.7-7</span></a>) for a function to get rid of these control characters.</p>

<p><a id="X81FB5BE27903EC32" name="X81FB5BE27903EC32"></a></p>

<h5>27.7-6 String</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; String</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
<p><code class="func">String</code> returns a representation of <var class="Arg">obj</var>, which may be an object of arbitrary type, as a string. This string should approximate as closely as possible the character sequence you see if you print <var class="Arg">obj</var>.</p>

<p>If <var class="Arg">length</var> is given it must be an integer. The absolute value gives the minimal length of the result. If the string representation of <var class="Arg">obj</var> takes less than that many characters it is filled with blanks. If <var class="Arg">length</var> is positive it is filled on the left, if <var class="Arg">length</var> is negative it is filled on the right.</p>

<p>In the two argument case, the string returned is a new mutable string (in particular not a part of any other object); it can be modified safely, and <code class="func">MakeImmutable</code> (<a href="chap12_mj.html#X80CE136D804097C7"><span class="RefLink">12.6-4</span></a>) may be safely applied to it.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">String(123);String([1,2,3]);</span>
"123"
"[ 1, 2, 3 ]"
</pre></div>

<p><code class="func">String</code> must not put in additional control characters <code class="code">\&lt;</code> (ASCII 1) and <code class="code">\&gt;</code> (ASCII 2) that allow proper line breaks.</p>

<p><a id="X86AACCE987F74FA5" name="X86AACCE987F74FA5"></a></p>

<h5>27.7-7 StripLineBreakCharacters</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StripLineBreakCharacters</code>( <var class="Arg">st</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>This function takes a string <var class="Arg">st</var> as an argument and removes all control characters <code class="code">\&lt;</code> (ASCII 1) and <code class="code">\&gt;</code> (ASCII 2) which are used by <code class="func">PrintString</code> (<a href="chap27_mj.html#X7B3CC87285DEC23D"><span class="RefLink">27.7-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to ensure proper line breaking. A new string with these characters removed is returned.</p>

<p><a id="X865FBB7E788017DD" name="X865FBB7E788017DD"></a></p>

<h5>27.7-8 HexStringInt</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; HexStringInt</code>( <var class="Arg">int</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a string which represents the integer <var class="Arg">int</var> with hexadecimal digits (using <code class="code">A</code> to <code class="code">F</code> as digits <code class="code">10</code> to <code class="code">15</code>). The inverse translation can be achieved with <code class="func">IntHexString</code> (<a href="chap27_mj.html#X796D366B7DDEFF67"><span class="RefLink">27.9-3</span></a>).</p>

<p><a id="X7BB1059185AB4F84" name="X7BB1059185AB4F84"></a></p>

<h5>27.7-9 StringPP</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringPP</code>( <var class="Arg">int</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a string representing the prime factor decomposition of the integer <var class="Arg">int</var>. See also <code class="func">PrintFactorsInt</code> (<a href="chap14_mj.html#X803D431087B6FF28"><span class="RefLink">14.4-10</span></a>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringPP(40320);</span>
"2^7*3^2*5*7"
</pre></div>

<p><a id="X79C8280A853D8FA9" name="X79C8280A853D8FA9"></a></p>

<h5>27.7-10 WordAlp</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; WordAlp</code>( <var class="Arg">alpha</var>, <var class="Arg">nr</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a string that is the <var class="Arg">nr</var>-th word over the alphabet list <var class="Arg">alpha</var>, w.r.t. word length and lexicographical order. The empty word is <code class="code">WordAlp( <var class="Arg">alpha</var>, 0 )</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">List([0..5],i-&gt;WordAlp("abc",i));</span>
[ "", "a", "b", "c", "aa", "ab" ]
</pre></div>

<p><a id="X798A0F35852ABDAD" name="X798A0F35852ABDAD"></a></p>

<h5>27.7-11 LowercaseString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; LowercaseString</code>( <var class="Arg">string</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns a lowercase version of the string <var class="Arg">string</var>, that is, a string in which each uppercase alphabet character is replaced by the corresponding lowercase character.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">LowercaseString("This Is UpperCase");</span>
"this is uppercase"
</pre></div>

<p><a id="X87A2F2557DE7EE08" name="X87A2F2557DE7EE08"></a></p>

<h5>27.7-12 LowercaseChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; LowercaseChar</code>( <var class="Arg">character</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns the lowercase version of the character <var class="Arg">character</var>.</p>

<p><a id="X7E7E5F5B7FED56A0" name="X7E7E5F5B7FED56A0"></a></p>

<h5>27.7-13 UppercaseString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; UppercaseString</code>( <var class="Arg">string</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns a uppercase version of the string <var class="Arg">string</var>, that is, a string in which each lowercase alphabet character is replaced by the corresponding uppercase character.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">UppercaseString("This Is UpperCase");</span>
"THIS IS UPPERCASE"
</pre></div>

<p><a id="X81E0AEE687200505" name="X81E0AEE687200505"></a></p>

<h5>27.7-14 UppercaseChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; UppercaseChar</code>( <var class="Arg">character</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns the uppercase version of the character <var class="Arg">character</var>.</p>

<p><a id="X86E897D486DCFEAB" name="X86E897D486DCFEAB"></a></p>

<h5>27.7-15 SplitString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SplitString</code>( <var class="Arg">string</var>, <var class="Arg">seps</var>[, <var class="Arg">wspace</var>] )</td><td class="tdright">(&nbsp;operation&nbsp;)</td></tr></table></div>
<p>This function accepts a string <var class="Arg">string</var> and lists <var class="Arg">seps</var> and, optionally, <var class="Arg">wspace</var> of characters. Now <var class="Arg">string</var> is split into substrings at each occurrence of a character in <var class="Arg">seps</var> or <var class="Arg">wspace</var>. The characters in <var class="Arg">wspace</var> are interpreted as white space characters. Substrings of characters in <var class="Arg">wspace</var> are treated as one white space character and they are ignored at the beginning and end of a string.</p>

<p>Both arguments <var class="Arg">seps</var> and <var class="Arg">wspace</var> can be single characters.</p>

<p>Each string in the resulting list of substring does not contain any characters in <var class="Arg">seps</var> or <var class="Arg">wspace</var>.</p>

<p>A character that occurs both in <var class="Arg">seps</var> and <var class="Arg">wspace</var> is treated as a white space character.</p>

<p>A separator at the end of a string is interpreted as a terminator; in this case, the separator does not produce a trailing empty string. Also seeĀ <code class="func">Chomp</code> (<a href="chap27_mj.html#X79F8FFC5876D854A"><span class="RefLink">27.7-21</span></a>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "substr1:substr2::substr4", ":" );</span>
[ "substr1", "substr2", "", "substr4" ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "a;b;c;d;", ";" );</span>
[ "a", "b", "c", "d" ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "/home//user//dir/", "", "/" );</span>
[ "home", "user", "dir" ]
</pre></div>

<p><a id="X864F0A9078D4DE0E" name="X864F0A9078D4DE0E"></a></p>

<h5>27.7-16 ReplacedString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; ReplacedString</code>( <var class="Arg">string</var>, <var class="Arg">old</var>, <var class="Arg">new</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>replaces occurrences of the string <var class="Arg">old</var> in <var class="Arg">string</var> by <var class="Arg">new</var>, starting from the left and always replacing the first occurrence. To avoid infinite recursion, characters which have been replaced already, are not subject to renewed replacement.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("abacab","a","zl");</span>
"zlbzlczlb"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("ababa", "aba","c");</span>
"cba"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("abacab","a","ba");</span>
"babbacbab"
</pre></div>

<p><a id="X806379367A53D171" name="X806379367A53D171"></a></p>

<h5>27.7-17 NormalizeWhitespace</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NormalizeWhitespace</code>( <var class="Arg">string</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>This function changes the string <var class="Arg">string</var> in place. The characters <code class="code"> </code> (space), <code class="code">\n</code>, <code class="code">\r</code> and <code class="code">\t</code> are considered as <em>white space</em>. Leading and trailing white space characters in <var class="Arg">string</var> are removed. Sequences of white space characters between other characters are replaced by a single space character.</p>

<p>See <code class="func">NormalizedWhitespace</code> (<a href="chap27_mj.html#X8685DE9386E57771"><span class="RefLink">27.7-18</span></a>) for a non-destructive version.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "   x y \n\n\t\r  z\n   \n";</span>
"   x y \n\n\t\r  z\n   \n"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NormalizeWhitespace(s);</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s;</span>
"x y z"
</pre></div>

<p><a id="X8685DE9386E57771" name="X8685DE9386E57771"></a></p>

<h5>27.7-18 NormalizedWhitespace</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NormalizedWhitespace</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>This function returns a copy of string <var class="Arg">str</var> to which <code class="func">NormalizeWhitespace</code> (<a href="chap27_mj.html#X806379367A53D171"><span class="RefLink">27.7-17</span></a>) was applied.</p>

<p><a id="X86EBB6EB829723E4" name="X86EBB6EB829723E4"></a></p>

<h5>27.7-19 RemoveCharacters</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; RemoveCharacters</code>( <var class="Arg">string</var>, <var class="Arg">chars</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Both arguments must be strings. This function efficiently removes all characters given in <var class="Arg">chars</var> from <var class="Arg">string</var>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "ab c\ndef\n\ng    h i .\n";</span>
"ab c\ndef\n\ng    h i .\n"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RemoveCharacters(s, " \n\t\r"); # remove all whitespace characters</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s;</span>
"abcdefghi."
</pre></div>

<p><a id="X84624FEB825EC4B5" name="X84624FEB825EC4B5"></a></p>

<h5>27.7-20 JoinStringsWithSeparator</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; JoinStringsWithSeparator</code>( <var class="Arg">list</var>[, <var class="Arg">sep</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>joins <var class="Arg">list</var> (a list of strings) after interpolating <var class="Arg">sep</var> (or <code class="code">","</code> if the second argument is omitted) between each adjacent pair of strings; <var class="Arg">sep</var> should be a string.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">list := List([1..10], String);</span>
[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">JoinStringsWithSeparator(list);</span>
"1,2,3,4,5,6,7,8,9,10"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">JoinStringsWithSeparator(["The", "quick", "brown", "fox"], " ");</span>
"The quick brown fox"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">new:= JoinStringsWithSeparator(["a", "b", "c", "d"], ",\n    ");</span>
"a,\n    b,\n    c,\n    d"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print("    ", new, "\n");</span>
    a,
    b,
    c,
    d
</pre></div>

<p><a id="X79F8FFC5876D854A" name="X79F8FFC5876D854A"></a></p>

<h5>27.7-21 Chomp</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Chomp</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Like the similarly named Perl function, <code class="func">Chomp</code> removes a trailing newline character (or carriage-return line-feed couplet) from a string argument <var class="Arg">str</var> if present and returns the result. If <var class="Arg">str</var> is not a string or does not have such trailing character(s) it is returned unchanged. This latter property means that <code class="func">Chomp</code> is safe to use in cases where one is manipulating the result of another function which might sometimes return <code class="keyw">fail</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\n");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\r\n");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(fail);</span>
fail
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(32);</span>
32
</pre></div>

<p><em>Note:</em> <code class="func">Chomp</code> only removes a trailing newline character from <var class="Arg">str</var>. If your string contains several newline characters and you really want to split <var class="Arg">str</var> into lines at the newline characters (and remove those newline characters) then you should use <code class="func">SplitString</code> (<a href="chap27_mj.html#X86E897D486DCFEAB"><span class="RefLink">27.7-15</span></a>), e.g.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">str := "The quick brown fox\njumps over the lazy dog.\n";</span>
"The quick brown fox\njumps over the lazy dog.\n"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString(str, "", "\n");</span>
[ "The quick brown fox", "jumps over the lazy dog." ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(str);</span>
"The quick brown fox\njumps over the lazy dog."
</pre></div>

<p><a id="X855820848179CC28" name="X855820848179CC28"></a></p>

<h5>27.7-22 StartsWith</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StartsWith</code>( <var class="Arg">string</var>, <var class="Arg">prefix</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; EndsWith</code>( <var class="Arg">string</var>, <var class="Arg">suffix</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Determines whether a string starts or ends with another string.</p>

<p><a id="X8235AD797868E872" name="X8235AD797868E872"></a></p>

<h5>27.7-23 StringFormatted</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringFormatted</code>( <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrintFormatted</code>( <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; PrintToFormatted</code>( <var class="Arg">stream</var>, <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>These functions perform a string formatting operation. They accept a format string, which can contain replacement fields which are delimited by braces {}. Each replacement field contains a numeric or positional argument, describing the element of <var class="Arg">data</var> to replace the braces with.</p>

<p>There are three formatting functions, which differ only in how they output the formatted string. <code class="func">StringFormatted</code> returns the formatted string, <code class="func">PrintFormatted</code> prints the formatted string and <code class="func">PrintToFormatted</code> appends the formatted string to <var class="Arg">stream</var>, which can be either an output stream or a filename.</p>

<p>The arguments after <var class="Arg">string</var> form a list <var class="Arg">data</var> of values used to substitute the replacement fields in <var class="Arg">string</var>, using the following formatting rules:</p>

<p><var class="Arg">string</var> is treated as a normal string, except for occurrences of <code class="code">{</code> and <code class="code">}</code>, which follow special rules, as follows:</p>

<p>The contents of <code class="code">{ }</code> is split by a <code class="code">!</code> into <code class="code">{id!format}</code>, where both <code class="code">id</code> and <code class="code">format</code> are optional. If the <code class="code">!</code> is omitted, the bracket is treated as <code class="code">{id}</code> with no <code class="code">format</code>.</p>

<p><code class="code">id</code> is interpreted as follows:</p>


<dl>
<dt><strong class="Mark">An integer <code class="code">i</code></strong></dt>
<dd><p>Take the <code class="code">i</code>th element of <var class="Arg">data</var>.</p>

</dd>
<dt><strong class="Mark">A string <code class="code">str</code></strong></dt>
<dd><p>If this is used, the first element of <var class="Arg">data</var> must be a record <code class="code">r</code>. In this case, the value <code class="code">r.(str)</code> is taken.</p>

</dd>
<dt><strong class="Mark">No id given</strong></dt>
<dd><p>Take the <code class="code">j</code>th element of <var class="Arg">data</var>, where <code class="code">j</code> is the number of replacement fields with no id in the format string so far. If any replacement field has no id, then all replacement fields must have no id.</p>

</dd>
</dl>
<p>A single brace can be outputted by doubling, so <code class="code">{{</code> in the format string produces <code class="code">{</code> and <code class="code">}}</code> produces <code class="code">}</code>.</p>

<p>The <code class="code">format</code> decides how the variable is printed. <code class="code">format</code> must be one of <code class="code">s</code> (which uses <code class="func">String</code> (<a href="chap27_mj.html#X81FB5BE27903EC32"><span class="RefLink">27.7-6</span></a>)), <code class="code">v</code> (which uses <code class="func">ViewString</code> (<a href="chap27_mj.html#X7803FBCA79DB5529"><span class="RefLink">27.7-3</span></a>)) or <code class="code">d</code> (which calls <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>)). The default value for <code class="code">format</code> is <code class="code">s</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {} cats and {} dogs", 4, 5);</span>
"I have 4 cats and 5 dogs"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {2} cats and {1} dogs", 4, 5);</span>
"I have 5 cats and 4 dogs"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {cats} cats and {dogs} dogs", rec(cats:=3, dogs:=2));</span>
"I have 3 cats and 2 dogs"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("We use {{ and }} to mark {dogs} dogs", rec(cats:=3, dogs:=2));</span>
"We use { and } to mark 2 dogs"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">sym3 := SymmetricGroup(3);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("String: {1!s}, ViewString: {1!v}", sym3);</span>
"String: SymmetricGroup( [ 1 .. 3 ] ), ViewString: Sym( [ 1 .. 3 ] )"
</pre></div>

<p>The following two functions convert basic strings to lists of numbers and vice versa. They are useful for examples of text encryption.</p>

<p><a id="X7848A9D878FD59BB" name="X7848A9D878FD59BB"></a></p>

<h5>27.7-24 NumbersString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; NumbersString</code>( <var class="Arg">s</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p><code class="func">NumbersString</code> takes a string message <var class="Arg">s</var> and returns a list of integers, each not exceeding the integer <var class="Arg">m</var> that encode the message using the scheme <span class="SimpleMath">\(A=11\)</span>, <span class="SimpleMath">\(B=12\)</span> and so on (and converting lower case to upper case). If a list of characters is given in <var class="Arg">table</var>, it is used instead for encoding).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l:=NumbersString("Twas brillig and the slithy toves",1000000);</span>
[ 303311, 291012, 281922, 221917, 101124, 141030, 181510, 292219,
  301835, 103025, 321529 ]
</pre></div>

<p><a id="X787EAB117816578E" name="X787EAB117816578E"></a></p>

<h5>27.7-25 StringNumbers</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringNumbers</code>( <var class="Arg">l</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p><code class="func">StringNumbers</code> takes a list <var class="Arg">l</var> of integers that was encoded using <code class="func">NumbersString</code> (<a href="chap27_mj.html#X7848A9D878FD59BB"><span class="RefLink">27.7-24</span></a>) and the size integer <var class="Arg">m</var>, and returns a message string, using the scheme <span class="SimpleMath">\(A=11\)</span>, <span class="SimpleMath">\(B=12\)</span> and so on. If a list of characters is given in <var class="Arg">table</var>, it is used instead for decoding).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringNumbers(l,1000000);</span>
"TWAS BRILLIG AND THE SLITHY TOVES"
</pre></div>

<p><a id="X82975B6480932683" name="X82975B6480932683"></a></p>

<h5>27.7-26 StringOfMemoryAmount</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringOfMemoryAmount</code>( <var class="Arg">numbytes</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>This function returns a human-readable string representing <var class="Arg">numbytes</var> of memory. It is used in printing amounts of memory allocated by tests and benchmarks. Binary prefixes (representing powers of 1024) are used.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringOfMemoryAmount(123456789);</span>
"117MB"
</pre></div>

<p><a id="X844BDC8578A3B508" name="X844BDC8578A3B508"></a></p>

<h4>27.8 <span class="Heading">Character Conversion</span></h4>

<p>The following functions convert characters in their internal integer values and vice versa. Note that the number corresponding to a particular character might depend on the system used. While most systems use an extension of ASCII, in particular character values outside the range <code class="code">[ 32 .. 126 ]</code> might differ between architectures.</p>

<p><a id="X826D95D680F87D23" name="X826D95D680F87D23"></a></p>

<h5>27.8-1 IntChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns an integer value in the range <code class="code">[ 0 .. 255 ]</code> that corresponds to <var class="Arg">char</var>.</p>

<p><a id="X87B6C1AF7E4A6639" name="X87B6C1AF7E4A6639"></a></p>

<h5>27.8-2 CharInt</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CharInt</code>( <var class="Arg">int</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a character that corresponds to the integer value <var class="Arg">int</var>, which must be in the range <code class="code">[ 0 .. 255 ]</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">c:=CharInt(65);</span>
'A'
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntChar(c);</span>
65
</pre></div>

<p><a id="X8159CE81798DDA76" name="X8159CE81798DDA76"></a></p>

<h5>27.8-3 SIntChar</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SIntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a signed integer value in the range <code class="code">[ -128 .. 127 ]</code> that corresponds to <var class="Arg">char</var>.</p>

<p><a id="X78E6611A829DDA3E" name="X78E6611A829DDA3E"></a></p>

<h5>27.8-4 CharSInt</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CharSInt</code>( <var class="Arg">int</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns a character which corresponds to the signed integer value <var class="Arg">int</var>, which must be in the range <code class="code">[ -128 .. 127 ]</code>.</p>

<p>The signed and unsigned integer functions behave the same for values in the range <code class="code">[ 0 .. 127 ]</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(c);</span>
65
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">c:=CharSInt(-20);;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(c);</span>
-20
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntChar(c);</span>
236
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(CharInt(255));</span>
-1
</pre></div>

<p><a id="X78D9BD857F890C0A" name="X78D9BD857F890C0A"></a></p>

<h4>27.9 <span class="Heading">Operations to Evaluate Strings</span></h4>

<p><a id="X7B6D118184F692A0" name="X7B6D118184F692A0"></a></p>

<h5>27.9-1 Int</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Int</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
<p>returns an integer as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by a sequence of decimal digits. For any other input <code class="keyw">fail</code> is returned.</p>

<p>For backwards compatibility, the empty string is accepted, in which case <span class="SimpleMath">\(0\)</span> is returned as result.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("12345");</span>
12345
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("123/45");</span>
fail
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("1+2");</span>
fail
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("-12");</span>
-12
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("");</span>
0
</pre></div>

<p><a id="X87AD395584294FF2" name="X87AD395584294FF2"></a></p>

<h5>27.9-2 Rat</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Rat</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;attribute&nbsp;)</td></tr></table></div>
<p>returns a rational as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by either a sequence of decimal digits or by two sequences of decimal digits that are separated by one of the characters <code class="code">/</code> or <code class="code">.</code>, where the latter stands for a decimal dot. For any other input <code class="keyw">fail</code> is returned.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat("123/45");</span>
41/15
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat("-123.45");</span>
-2469/20
</pre></div>

<p><a id="X796D366B7DDEFF67" name="X796D366B7DDEFF67"></a></p>

<h5>27.9-3 IntHexString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; IntHexString</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns an integer as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by a sequence of hexadecimal digits. Here the letters <code class="code">a</code>-<code class="code">f</code> or <code class="code">A</code>-<code class="code">F</code> are used as <em>digits</em> <span class="SimpleMath">\(10\)</span> to <span class="SimpleMath">\(15\)</span>. Any other input results in an error.</p>

<p>This function can be used (together with <code class="func">HexStringInt</code> (<a href="chap27_mj.html#X865FBB7E788017DD"><span class="RefLink">27.7-8</span></a>)) for efficiently storing and reading large integers from respectively into <strong class="pkg">GAP</strong>. Note that the translation between integers and their hexadecimal representation costs linear computation time in terms of the number of digits, while translation from and into decimal representation needs substantial computations.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntHexString("-abcdef0123456789");</span>
-12379813738877118345
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexStringInt(last);</span>
"-ABCDEF0123456789"
</pre></div>

<p><a id="X7C0C29C87CBA97B7" name="X7C0C29C87CBA97B7"></a></p>

<h5>27.9-4 Ordinal</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Ordinal</code>( <var class="Arg">n</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the ordinal of the integer <var class="Arg">n</var> as a string.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Ordinal(2);  Ordinal(21);  Ordinal(33);  Ordinal(-33);</span>
"2nd"
"21st"
"33rd"
"-33rd"
</pre></div>

<p><a id="X7DE4CCD285440659" name="X7DE4CCD285440659"></a></p>

<h5>27.9-5 EvalString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; EvalString</code>( <var class="Arg">expr</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>passes the string <var class="Arg">expr</var> through an input text stream so that <strong class="pkg">GAP</strong> interprets it, and returns the result.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">a:=10;</span>
10
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">EvalString("a^2");</span>
100
</pre></div>

<p><code class="func">EvalString</code> is intended for <em>single</em> expressions. A sequence of commands may be interpreted by using the functions <code class="func">InputTextString</code> (<a href="chap10_mj.html#X7ABABCDF7ED81F7F"><span class="RefLink">10.7-1</span></a>) and <code class="func">ReadAsFunction</code> (<a href="chap10_mj.html#X7D62F2877F0E45A7"><span class="RefLink">10.3-2</span></a>) together; see <a href="chap10_mj.html#X7D1D33A587BFD93D"><span class="RefLink">10.3</span></a> for an example.</p>

<p>If <code class="func">EvalString</code> is used inside a function, then it doesn't know about the local variables and the arguments of the function. A possible workaround is to define global variables in advance, and then to assign the values of the local variables to the global ones, like in the example below.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">global_a := 0;;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">global_b := 0;;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">example := function ( local_a )</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">    local  local_b;</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">    local_b := 5;</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">    global_a := local_a;</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">    global_b := local_b;</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">    return EvalString( "global_a * global_b" );</span>
<span class="GAPprompt">&gt;</span> <span class="GAPinput">end;;</span>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">example( 2 );</span>
10
</pre></div>

<p><a id="X7D4B9D7A7995C55D" name="X7D4B9D7A7995C55D"></a></p>

<h5>27.9-6 CrcString</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; CrcString</code>( <var class="Arg">str</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns: an integer</p>

<p>This function computes a CRC (cyclic redundancy check) number from a string <var class="Arg">str</var>. See also <code class="func">CrcFile</code> (<a href="chap9_mj.html#X8241CEAD80415BB9"><span class="RefLink">9.8-7</span></a>) and <code class="func">HexSHA256</code> (<a href="chap27_mj.html#X7873D1F28779B490"><span class="RefLink">27.9-7</span></a>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CrcString("GAP example string");</span>
-50451670
</pre></div>

<p><a id="X7873D1F28779B490" name="X7873D1F28779B490"></a></p>

<h5>27.9-7 HexSHA256</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; HexSHA256</code>( <var class="Arg">string</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; HexSHA256</code>( <var class="Arg">stream</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Return the SHA-256 cryptographic checksum of the bytes in <var class="Arg">string</var>, resp. of the data in the input stream object <var class="Arg">stream</var> (see ChapterĀ <a href="chap10_mj.html#X839725177BF8B5B4"><span class="RefLink">10</span></a> to learn about streams) when read from the current position until EOF (end-of-file).</p>

<p>The checksum is returned as string with 64 lowercase hexadecimal digits.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexSHA256("abcd");</span>
"88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexSHA256(InputTextString("abcd"));</span>
"88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"
</pre></div>

<p><a id="X83FF17E782E6FFF3" name="X83FF17E782E6FFF3"></a></p>

<h5>27.9-8 Pluralize</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; Pluralize</code>( [<var class="Arg">count</var>, ]<var class="Arg">string</var>[, <var class="Arg">plural</var>] )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>Returns: A string</p>

<p>This function returns an attempt at the appropriate pluralization of a string (considered as a singular English noun), using several rules and heuristics of English grammar.</p>

<p>The arguments to this function are an optional non-negative integer <var class="Arg">count</var> (the number of objects in question), a non-empty string <var class="Arg">string</var> (the singular form of the object in question), and an optional additional string <var class="Arg">plural</var> (the plural form of <var class="Arg">string</var>).</p>

<p>If <var class="Arg">plural</var> is given, then <code class="code">Pluralize</code> uses it as the plural form of <var class="Arg">string</var>, otherwise <code class="code">Pluralize</code> makes an informed guess at the plural.</p>

<p>If <var class="Arg">count</var> is not given, then <code class="code">Pluralize</code> returns this plural form of <var class="Arg">string</var>. If <var class="Arg">count</var> is given and has value <span class="SimpleMath">\(n \neq 1\)</span>, then this string is prepended by "\&gt;n\&lt; "; else if <var class="Arg">count</var> has value <span class="SimpleMath">\(1\)</span>, then <code class="code">Pluralize</code> returns <var class="Arg">string</var>, prepended by "\&gt;1\&lt; ".</p>

<p>Note that <code class="func">StripLineBreakCharacters</code> (<a href="chap27_mj.html#X86AACCE987F74FA5"><span class="RefLink">27.7-7</span></a>) can be used to remove the control characters <code class="code">\&lt;</code> and <code class="code">\&gt;</code> from the return value.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( "generator" );</span>
"generators"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 1, "generator" );</span>
"\&gt;1\&lt; generator"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 0, "generator" );</span>
"\&gt;0\&lt; generators"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( "man", "men" );</span>
"men"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 1, "man", "men" );</span>
"\&gt;1\&lt; man"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 2, "man", "men" ) );</span>
2 men
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 2, "vertex" ) );</span>
2 vertices
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 3, "matrix" ) );</span>
3 matrices
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 4, "battery" ) );</span>
4 batteries
</pre></div>

<p><a id="X78F20AA1804D524F" name="X78F20AA1804D524F"></a></p>

<h4>27.10 <span class="Heading">Calendar Arithmetic</span></h4>

<p>All calendar functions use the Gregorian calendar.</p>

<p><a id="X87BA46787FF000E8" name="X87BA46787FF000E8"></a></p>

<h5>27.10-1 DaysInYear</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DaysInYear</code>( <var class="Arg">year</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the number of days in the year <var class="Arg">year</var>.</p>

<p><a id="X8791B0B386D59ADB" name="X8791B0B386D59ADB"></a></p>

<h5>27.10-2 DaysInMonth</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DaysInMonth</code>( <var class="Arg">month</var>, <var class="Arg">year</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the number of days in month number <var class="Arg">month</var> of <var class="Arg">year</var>, and <code class="keyw">fail</code> if <code class="code">month</code> is not in the valid range.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DaysInYear(1998);</span>
365
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DaysInMonth(3,1998);</span>
31
</pre></div>

<p><a id="X7CED84C07CD5E2CF" name="X7CED84C07CD5E2CF"></a></p>

<h5>27.10-3 DMYDay</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DMYDay</code>( <var class="Arg">day</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>converts a number of days, starting 1-Jan-1970, to a list <code class="code">[ day, month, year ]</code> in Gregorian calendar counting.</p>

<p><a id="X7A79DEE07A41B8EF" name="X7A79DEE07A41B8EF"></a></p>

<h5>27.10-4 DayDMY</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DayDMY</code>( <var class="Arg">dmy</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the number of days from 01-Jan-1970 to the day given by <var class="Arg">dmy</var>, which must be a list of the form <code class="code">[ day, month, year ]</code> in Gregorian calendar counting. The result is <code class="keyw">fail</code> on input outside valid ranges.</p>

<p>Note that this makes not much sense for early dates like: before 1582 (no Gregorian calendar at all), or before 1753 in many English speaking countries or before 1917 in Russia.</p>

<p><a id="X87D03FC0809DB6EC" name="X87D03FC0809DB6EC"></a></p>

<h5>27.10-5 WeekDay</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; WeekDay</code>( <var class="Arg">date</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the weekday of a day given by <var class="Arg">date</var>, which can be a number of days since 1-Jan-1970 or a list <code class="code">[ day, month, year ]</code>.</p>

<p><a id="X7C74C33784CDED6C" name="X7C74C33784CDED6C"></a></p>

<h5>27.10-6 StringDate</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringDate</code>( <var class="Arg">date</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>converts <var class="Arg">date</var> to a readable string. <var class="Arg">date</var> can be a number of days since 1-Jan-1970 or a list <code class="code">[ day, month, year ]</code>.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DayDMY([1,1,1970]);DayDMY([2,1,1970]);</span>
0
1
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DMYDay(12345);</span>
[ 20, 10, 2003 ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">WeekDay([11,3,1998]);</span>
"Wed"
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringDate([11,3,1998]);</span>
"11-Mar-1998"
</pre></div>

<p><a id="X84A6A2637FB35A32" name="X84A6A2637FB35A32"></a></p>

<h5>27.10-7 HMSMSec</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; HMSMSec</code>( <var class="Arg">msec</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>converts a number <var class="Arg">msec</var> of milliseconds into a list <code class="code">[ hour, min, sec, milli ]</code>.</p>

<p><a id="X879461D77C81100B" name="X879461D77C81100B"></a></p>

<h5>27.10-8 SecHMSM</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SecHMSM</code>( <var class="Arg">hmsm</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>is the reverse of <code class="func">HMSMSec</code> (<a href="chap27_mj.html#X84A6A2637FB35A32"><span class="RefLink">27.10-7</span></a>).</p>

<p><a id="X802469C47F886A59" name="X802469C47F886A59"></a></p>

<h5>27.10-9 StringTime</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; StringTime</code>( <var class="Arg">time</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>converts <var class="Arg">time</var> (given as a number of milliseconds or a list <code class="code">[ hour, min, sec, milli ]</code>) to a readable string.</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HMSMSec(Factorial(10));</span>
[ 1, 0, 28, 800 ]
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SecHMSM([1,10,5,13]);</span>
4205013
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringTime([1,10,5,13]);</span>
" 1:10:05.013"
</pre></div>

<p><a id="X870A71D47B0E936E" name="X870A71D47B0E936E"></a></p>

<h5>27.10-10 SecondsDMYhms</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; SecondsDMYhms</code>( <var class="Arg">DMYhms</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>returns the number of seconds from 01-Jan-1970, 00:00:00, to the time given by <var class="Arg">DMYhms</var>, which must be a list of the form <code class="code">[ day, month, year, hour, minute, second ]</code>. The remarks on the Gregorian calendar in the section on <code class="func">DayDMY</code> (<a href="chap27_mj.html#X7A79DEE07A41B8EF"><span class="RefLink">27.10-4</span></a>) apply here as well. The last three arguments must lie in the appropriate ranges.</p>

<p><a id="X78AF8EA887532B5B" name="X78AF8EA887532B5B"></a></p>

<h5>27.10-11 DMYhmsSeconds</h5>

<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">&#8227; DMYhmsSeconds</code>( <var class="Arg">secs</var> )</td><td class="tdright">(&nbsp;function&nbsp;)</td></tr></table></div>
<p>This is the inverse function to <code class="func">SecondsDMYhms</code> (<a href="chap27_mj.html#X870A71D47B0E936E"><span class="RefLink">27.10-10</span></a>).</p>


<div class="example"><pre>
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SecondsDMYhms([ 9, 9, 2001, 1, 46, 40 ]);</span>
1000000000
<span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DMYhmsSeconds(-1000000000);</span>
[ 24, 4, 1938, 22, 13, 20 ]
</pre></div>

<p><a id="X78024C8087F3E07F" name="X78024C8087F3E07F"></a></p>

<h4>27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></h4>

<p>For the purpose of generating LaTeX source code with <strong class="pkg">GAP</strong> it is recommended to add new functions which will print the LaTeX source or return LaTeX strings for further processing.</p>

<p>An alternative approach could be based on methods for the default LaTeX representation for each appropriate type of objects. However, there is no clear notion of a default LaTeX code for any non-trivial mathematical object; moreover, different output may be required in different contexts.</p>

<p>While customisation of such an operation may require changes in a variety of methods that may be distributed all over the library, the user will have a clean overview of the whole process of LaTeX code generation if it is contained in a single function. Furthermore, there may be kinds of objects which are not detected by the method selection, or there may be a need in additional parameters specifying requirements for the output.</p>

<p>This is why having a special purpose function for each particular case is more suitable. <strong class="pkg">GAP</strong> provides several functions that produce LaTeX strings for those situations where this is nontrivial and reasonable. A useful example is <code class="func">LaTeXStringDecompositionMatrix</code> (<a href="chap71_mj.html#X83EC921380AF9B3B"><span class="RefLink">71.11-5</span></a>) from the <strong class="pkg">GAP</strong> library, others can be found entering <code class="code">?LaTeX</code> at the <strong class="pkg">GAP</strong> prompt. Package authors are encouraged to add an index entry <code class="code">LaTeX</code> to the documentation of all LaTeX string producing functions. This way, entering <code class="code">?LaTeX</code> will give an overview of all documented functionality in this direction.</p>


<div class="chlinkprevnextbot">&nbsp;<a href="chap0_mj.html">[Top of Book]</a>&nbsp;  <a href="chap0_mj.html#contents">[Contents]</a>&nbsp;  &nbsp;<a href="chap26_mj.html">[Previous Chapter]</a>&nbsp;  &nbsp;<a href="chap28_mj.html">[Next Chapter]</a>&nbsp;  </div>


<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a>  <a href="chap1_mj.html">1</a>  <a href="chap2_mj.html">2</a>  <a href="chap3_mj.html">3</a>  <a href="chap4_mj.html">4</a>  <a href="chap5_mj.html">5</a>  <a href="chap6_mj.html">6</a>  <a href="chap7_mj.html">7</a>  <a href="chap8_mj.html">8</a>  <a href="chap9_mj.html">9</a>  <a href="chap10_mj.html">10</a>  <a href="chap11_mj.html">11</a>  <a href="chap12_mj.html">12</a>  <a href="chap13_mj.html">13</a>  <a href="chap14_mj.html">14</a>  <a href="chap15_mj.html">15</a>  <a href="chap16_mj.html">16</a>  <a href="chap17_mj.html">17</a>  <a href="chap18_mj.html">18</a>  <a href="chap19_mj.html">19</a>  <a href="chap20_mj.html">20</a>  <a href="chap21_mj.html">21</a>  <a href="chap22_mj.html">22</a>  <a href="chap23_mj.html">23</a>  <a href="chap24_mj.html">24</a>  <a href="chap25_mj.html">25</a>  <a href="chap26_mj.html">26</a>  <a href="chap27_mj.html">27</a>  <a href="chap28_mj.html">28</a>  <a href="chap29_mj.html">29</a>  <a href="chap30_mj.html">30</a>  <a href="chap31_mj.html">31</a>  <a href="chap32_mj.html">32</a>  <a href="chap33_mj.html">33</a>  <a href="chap34_mj.html">34</a>  <a href="chap35_mj.html">35</a>  <a href="chap36_mj.html">36</a>  <a href="chap37_mj.html">37</a>  <a href="chap38_mj.html">38</a>  <a href="chap39_mj.html">39</a>  <a href="chap40_mj.html">40</a>  <a href="chap41_mj.html">41</a>  <a href="chap42_mj.html">42</a>  <a href="chap43_mj.html">43</a>  <a href="chap44_mj.html">44</a>  <a href="chap45_mj.html">45</a>  <a href="chap46_mj.html">46</a>  <a href="chap47_mj.html">47</a>  <a href="chap48_mj.html">48</a>  <a href="chap49_mj.html">49</a>  <a href="chap50_mj.html">50</a>  <a href="chap51_mj.html">51</a>  <a href="chap52_mj.html">52</a>  <a href="chap53_mj.html">53</a>  <a href="chap54_mj.html">54</a>  <a href="chap55_mj.html">55</a>  <a href="chap56_mj.html">56</a>  <a href="chap57_mj.html">57</a>  <a href="chap58_mj.html">58</a>  <a href="chap59_mj.html">59</a>  <a href="chap60_mj.html">60</a>  <a href="chap61_mj.html">61</a>  <a href="chap62_mj.html">62</a>  <a href="chap63_mj.html">63</a>  <a href="chap64_mj.html">64</a>  <a href="chap65_mj.html">65</a>  <a href="chap66_mj.html">66</a>  <a href="chap67_mj.html">67</a>  <a href="chap68_mj.html">68</a>  <a href="chap69_mj.html">69</a>  <a href="chap70_mj.html">70</a>  <a href="chap71_mj.html">71</a>  <a href="chap72_mj.html">72</a>  <a href="chap73_mj.html">73</a>  <a href="chap74_mj.html">74</a>  <a href="chap75_mj.html">75</a>  <a href="chap76_mj.html">76</a>  <a href="chap77_mj.html">77</a>  <a href="chap78_mj.html">78</a>  <a href="chap79_mj.html">79</a>  <a href="chap80_mj.html">80</a>  <a href="chap81_mj.html">81</a>  <a href="chap82_mj.html">82</a>  <a href="chap83_mj.html">83</a>  <a href="chap84_mj.html">84</a>  <a href="chap85_mj.html">85</a>  <a href="chap86_mj.html">86</a>  <a href="chap87_mj.html">87</a>  <a href="chapBib_mj.html">Bib</a>  <a href="chapInd_mj.html">Ind</a>  </div>

<hr />
<p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>