/usr/share/gap/doc/ref/chap27.html is in gap-doc 4r8p6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | <?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>
<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.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap26.html">[Previous Chapter]</a> <a href="chap28.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap27_mj.html">[MathJax on]</a></p>
<p><a id="X7D28329B7EDB8F47" name="X7D28329B7EDB8F47"></a></p>
<div class="ChapSects"><a href="chap27.html#X7D28329B7EDB8F47">27 <span class="Heading">Strings and Characters</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X7A90690B78260194">27.1 <span class="Heading">IsChar and IsString</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X80CFAE128560E064">27.1-1 IsChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X78723B5D795A3B6D">27.1-2 IsString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7B1B45C587A72F96">27.1-3 <span class="Heading">Strings As Lists</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7EA6CA7486D7E9DD">27.1-4 <span class="Heading">Printing Strings</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X82E5F5AB818F32DB">27.2 <span class="Heading">Special Characters</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X7E70384E7D0B7083">27.3 <span class="Heading">Triple Quoted Strings</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X82AEC07487C45ECD">27.4 <span class="Heading">Internally Represented Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7A17EDF8785C9F58">27.4-1 IsStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7CE2415F7FEC5809">27.4-2 ConvertToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7FFC464683CC8023">27.4-3 CopyToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7D944D507CBB24CD">27.4-4 IsEmptyString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X836078DC829A8221">27.4-5 EmptyString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7DA671FC7F490C16">27.4-6 CharsFamily</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X82F980A17FE84AA4">27.5 <span class="Heading">Recognizing Characters</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X78566FD57B95ECBE">27.5-1 IsDigitChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X854114A97BAFEAEA">27.5-2 IsLowerAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X87B1A13D81353AD8">27.5-3 IsUpperAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X84634DF67A431D26">27.5-4 IsAlphaChar</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X8127954B79B8A0DA">27.6 <span class="Heading">Comparisons of Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X79538F138286739A">27.6-1 \=</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X8129E3A785F60093">27.6-2 \<</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.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"> </span><a href="chap27.html#X792FB3A1849FD739">27.7-1 DisplayString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X8482132779EA7A23">27.7-2 DEFAULTDISPLAYSTRING</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7803FBCA79DB5529">27.7-3 ViewString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7BBDF9D383595425">27.7-4 DEFAULTVIEWSTRING</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7B3CC87285DEC23D">27.7-5 PrintString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X81FB5BE27903EC32">27.7-6 String</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X86AACCE987F74FA5">27.7-7 StripLineBreakCharacters</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X865FBB7E788017DD">27.7-8 HexStringInt</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7BB1059185AB4F84">27.7-9 StringPP</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X79C8280A853D8FA9">27.7-10 WordAlp</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X798A0F35852ABDAD">27.7-11 LowercaseString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X86E897D486DCFEAB">27.7-12 SplitString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X864F0A9078D4DE0E">27.7-13 ReplacedString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X806379367A53D171">27.7-14 NormalizeWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X8685DE9386E57771">27.7-15 NormalizedWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X86EBB6EB829723E4">27.7-16 RemoveCharacters</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X84624FEB825EC4B5">27.7-17 JoinStringsWithSeparator</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X79F8FFC5876D854A">27.7-18 Chomp</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X855820848179CC28">27.7-19 StartsWith</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7848A9D878FD59BB">27.7-20 NumbersString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X787EAB117816578E">27.7-21 StringNumbers</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X844BDC8578A3B508">27.8 <span class="Heading">Character Conversion</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X826D95D680F87D23">27.8-1 IntChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X87B6C1AF7E4A6639">27.8-2 CharInt</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X8159CE81798DDA76">27.8-3 SIntChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X78E6611A829DDA3E">27.8-4 CharSInt</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X78D9BD857F890C0A">27.9 <span class="Heading">Operations to Evaluate Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7B6D118184F692A0">27.9-1 Int</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7C0C29C87CBA97B7">27.9-2 Ordinal</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7DE4CCD285440659">27.9-3 EvalString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7D4B9D7A7995C55D">27.9-4 CrcString</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.html#X78F20AA1804D524F">27.10 <span class="Heading">Calendar Arithmetic</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X87BA46787FF000E8">27.10-1 DaysInYear</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X8791B0B386D59ADB">27.10-2 DaysInMonth</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7CED84C07CD5E2CF">27.10-3 DMYDay</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7A79DEE07A41B8EF">27.10-4 DayDMY</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X87D03FC0809DB6EC">27.10-5 WeekDay</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X7C74C33784CDED6C">27.10-6 StringDate</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X84A6A2637FB35A32">27.10-7 HMSMSec</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X879461D77C81100B">27.10-8 SecHMSM</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X802469C47F886A59">27.10-9 StringTime</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X870A71D47B0E936E">27.10-10 SecondsDMYhms</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27.html#X78AF8EA887532B5B">27.10-11 DMYhmsSeconds</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27.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">‣ IsChar</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsCharCollection</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</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></span> <span class="GAPinput">x:= 'a'; IsChar( x );</span>
'a'
true
<span class="GAPprompt">gap></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">‣ IsString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p>A <em>string</em> is a dense list (see <code class="func">IsList</code> (<a href="chap21.html#X7C4CC4EA8299701E"><span class="RefLink">21.1-1</span></a>), <code class="func">IsDenseList</code> (<a href="chap21.html#X870AA9D8798C93DD"><span class="RefLink">21.1-2</span></a>)) of characters (see <code class="func">IsChar</code> (<a href="chap27.html#X80CFAE128560E064"><span class="RefLink">27.1-1</span></a>)); thus strings are always homogeneous (see <code class="func">IsHomogeneousList</code> (<a href="chap21.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.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. And for some special characters (like the newline character) there is a further possibility to type them, see section <a href="chap27.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s1 := ['H','e','l','l','o',' ','w','o','r','l','d','.'];</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( s1 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">s2 := "Hello world.";</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">s1 = s2;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">s3 := ""; # the empty string</span>
""
<span class="GAPprompt">gap></span> <span class="GAPinput">s3 = [];</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( "123" ); IsString( 123 );</span>
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [ '1', '2', '3' ] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [ '1', '2', , '4' ] ); # strings must be dense</span>
false
<span class="GAPprompt">gap></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.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.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>), test for membership (see <a href="chap30.html#X82D39CF980FDBFFA"><span class="RefLink">30.6</span></a>), ask for the length, concatenate strings (see <code class="func">Concatenation</code> (<a href="chap21.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.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></span> <span class="GAPinput">Length( s2 );</span>
12
<span class="GAPprompt">gap></span> <span class="GAPinput">s2[2];</span>
'e'
<span class="GAPprompt">gap></span> <span class="GAPinput">'a' in s2;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">s2[2] := 'a';; s2;</span>
"Hallo world."
<span class="GAPprompt">gap></span> <span class="GAPinput">s1{ [1..4] };</span>
"Hell"
<span class="GAPprompt">gap></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">‣ ViewObj</code>( <var class="Arg">str</var> )</td><td class="tdright">( method )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrintObj</code>( <var class="Arg">str</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>If a string is displayed by <code class="func">View</code> (<a href="chap6.html#X851902C583B84CDC"><span class="RefLink">6.3-3</span></a>), for example as result of an evaluation (see <a href="chap6.html#X81667F568237B232"><span class="RefLink">6.1</span></a>), or by <code class="func">ViewObj</code> (<a href="chap6.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6.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.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.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.7-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></span> <span class="GAPinput">s4:= "abc\"def\nghi";;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">View( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">ViewObj( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintObj( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( s4 ); Print( "\n" );</span>
abc"def
ghi
<span class="GAPprompt">gap></span> <span class="GAPinput">s := "German uses strange characters: äöüß\n";</span>
"German uses strange characters: äöüß\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print(s);</span>
German uses strange characters: äöüß
<span class="GAPprompt">gap></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></span> <span class="GAPinput">s := "\007";</span>
"\007"
<span class="GAPprompt">gap></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.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.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></span> <span class="GAPinput">s1;</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( s1 );</span>
Hello world.gap> Print( s1, "\n" );
Hello world.
<span class="GAPprompt">gap></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 two characters. The first is a backslash <code class="code">\</code>. The second may be any character. If it is an octal digit (from <code class="code">0</code> to <code class="code">7</code>) there must be two more such digits. The meaning is given in the following list</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. 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">
other</strong></dt>
<dd><p>For any other character the backslash is simply 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.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>) send the characters directly to the output stream.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></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></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.html#X866092F281910B74"><span class="RefLink">6.2</span></a>. The rules on escaping are ignored in a triple quoted string, see <a href="chap27.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.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></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.html#X866092F281910B74"><span class="RefLink">6.2</span></a>), which state that in normal line editing mode, lines starting <code class="code">gap> </code>, <code class="code">> </code> or <code class="code">brk> </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">‣ IsStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( representation )</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.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>). Note that calling <code class="func">IsString</code> (<a href="chap27.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">‣ ConvertToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</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.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="code">IsPlistRep</code>, to <code class="func">IsStringRep</code> (<a href="chap27.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">‣ CopyToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</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.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">‣ IsEmptyString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</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.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></span> <span class="GAPinput">l:= [];; IsString( l ); IsEmptyString( l ); IsEmpty( l );</span>
true
false
true
<span class="GAPprompt">gap></span> <span class="GAPinput">l; ConvertToStringRep( l ); l;</span>
[ ]
""
<span class="GAPprompt">gap></span> <span class="GAPinput">IsEmptyString( l ); IsEmptyString( "" ); IsEmptyString( "abc" );</span>
true
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ll:= [ 'a', 'b' ]; IsStringRep( ll ); ConvertToStringRep( ll );</span>
"ab"
false
<span class="GAPprompt">gap></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">‣ EmptyString</code>( <var class="Arg">len</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a string</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ShrinkAllocationString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</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 analogeous functions <code class="func">EmptyPlist</code> (<a href="chap21.html#X78BF67A5802E93AD"><span class="RefLink">21.9-1</span></a>) and <code class="func">ShrinkAllocationPlist</code> (<a href="chap21.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">‣ CharsFamily</code></td><td class="tdright">( family )</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">‣ IsDigitChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</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">‣ IsLowerAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</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">‣ IsUpperAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</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">‣ IsAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</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>27.6-1 \=</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \=</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">( method )</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"><></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></span> <span class="GAPinput">"Hello world.\n" = "Hello world.\n";</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello World.\n" = "Hello world.\n"; # comparison is case sensitive</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world." = "Hello world.\n"; # first string has no <newline></span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">"Goodbye world.\n" = "Hello world.\n";</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 'a', 'b' ] = "ab";</span>
true
</pre></div>
<p><a id="X8129E3A785F60093" name="X8129E3A785F60093"></a></p>
<h5>27.6-2 \<</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \<</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">( method )</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></span> <span class="GAPinput">"Hello world.\n" < "Hello world.\n"; # the strings are equal</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput"># in ASCII capitals range before small letters:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello World." < "Hello world.";</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world." < "Hello world.\n"; # prefixes are always smaller</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput"># G comes before H, in ASCII at least:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Goodbye world.\n" < "Hello world.\n";</span>
true
</pre></div>
<p>Strings can be compared via <code class="code"><</code> with certain <strong class="pkg">GAP</strong> objects that are not strings, see <a href="chap4.html#X7A274A1F8553B7E6"><span class="RefLink">4.12</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.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">‣ DisplayString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</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.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) or <code class="func">PrintObj</code> (<a href="chap6.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">‣ DEFAULTDISPLAYSTRING</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This is the default value for <code class="func">DisplayString</code> (<a href="chap27.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">‣ ViewString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</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.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.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>), <code class="func">DisplayString</code> (<a href="chap27.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>) or <code class="func">PrintObj</code> (<a href="chap6.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">‣ DEFAULTVIEWSTRING</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This is the default value for <code class="func">ViewString</code> (<a href="chap27.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">‣ PrintString</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">( operation )</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.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.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></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">\<</code> (ASCII 1) and <code class="code">\></code> (ASCII 2) that allow proper line breaks. See <code class="func">StripLineBreakCharacters</code> (<a href="chap27.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">‣ String</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">( attribute )</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.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></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">\<</code> (ASCII 1) and <code class="code">\></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">‣ StripLineBreakCharacters</code>( <var class="Arg">st</var> )</td><td class="tdright">( function )</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">\<</code> (ASCII 1) and <code class="code">\></code> (ASCII 2) which are used by <code class="func">PrintString</code> (<a href="chap27.html#X7B3CC87285DEC23D"><span class="RefLink">27.7-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6.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">‣ HexStringInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string which represents the integer <var class="Arg">int</var> with hexa-decimal 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.html#X7B6D118184F692A0"><span class="RefLink">27.9-1</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">‣ StringPP</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string representing the prime factor decomposition of the integer <var class="Arg">int</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></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">‣ WordAlp</code>( <var class="Arg">alpha</var>, <var class="Arg">nr</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">List([0..5],i->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">‣ LowercaseString</code>( <var class="Arg">string</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">LowercaseString("This Is UpperCase");</span>
"this is uppercase"
</pre></div>
<p><a id="X86E897D486DCFEAB" name="X86E897D486DCFEAB"></a></p>
<h5>27.7-12 SplitString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SplitString</code>( <var class="Arg">string</var>, <var class="Arg">seps</var>[, <var class="Arg">wspace</var>] )</td><td class="tdright">( operation )</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.html#X79F8FFC5876D854A"><span class="RefLink">27.7-18</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString( "substr1:substr2::substr4", ":" );</span>
[ "substr1", "substr2", "", "substr4" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString( "a;b;c;d;", ";" );</span>
[ "a", "b", "c", "d" ]
<span class="GAPprompt">gap></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-13 ReplacedString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReplacedString</code>( <var class="Arg">string</var>, <var class="Arg">old</var>, <var class="Arg">new</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">ReplacedString("abacab","a","zl");</span>
"zlbzlczlb"
<span class="GAPprompt">gap></span> <span class="GAPinput">ReplacedString("ababa", "aba","c");</span>
"cba"
<span class="GAPprompt">gap></span> <span class="GAPinput">ReplacedString("abacab","a","ba");</span>
"babbacbab"
</pre></div>
<p><a id="X806379367A53D171" name="X806379367A53D171"></a></p>
<h5>27.7-14 NormalizeWhitespace</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NormalizeWhitespace</code>( <var class="Arg">string</var> )</td><td class="tdright">( function )</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.html#X8685DE9386E57771"><span class="RefLink">27.7-15</span></a>) for a non-destructive version.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></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></span> <span class="GAPinput">NormalizeWhitespace(s);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span>
"x y z"
</pre></div>
<p><a id="X8685DE9386E57771" name="X8685DE9386E57771"></a></p>
<h5>27.7-15 NormalizedWhitespace</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NormalizedWhitespace</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</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.html#X806379367A53D171"><span class="RefLink">27.7-14</span></a>) was applied.</p>
<p><a id="X86EBB6EB829723E4" name="X86EBB6EB829723E4"></a></p>
<h5>27.7-16 RemoveCharacters</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RemoveCharacters</code>( <var class="Arg">string</var>, <var class="Arg">chars</var> )</td><td class="tdright">( function )</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></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></span> <span class="GAPinput">RemoveCharacters(s, " \n\t\r"); # remove all whitespace characters</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span>
"abcdefghi."
</pre></div>
<p><a id="X84624FEB825EC4B5" name="X84624FEB825EC4B5"></a></p>
<h5>27.7-17 JoinStringsWithSeparator</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JoinStringsWithSeparator</code>( <var class="Arg">list</var>[, <var class="Arg">sep</var>] )</td><td class="tdright">( function )</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></span> <span class="GAPinput">list := List([1..10], String);</span>
[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">JoinStringsWithSeparator(list);</span>
"1,2,3,4,5,6,7,8,9,10"
<span class="GAPprompt">gap></span> <span class="GAPinput">JoinStringsWithSeparator(["The", "quick", "brown", "fox"], " ");</span>
"The quick brown fox"
<span class="GAPprompt">gap></span> <span class="GAPinput">new:= JoinStringsWithSeparator(["a", "b", "c", "d"], ",\n ");</span>
"a,\n b,\n c,\n d"
<span class="GAPprompt">gap></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-18 Chomp</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Chomp</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</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></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></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></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></span> <span class="GAPinput">Chomp(fail);</span>
fail
<span class="GAPprompt">gap></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.html#X86E897D486DCFEAB"><span class="RefLink">27.7-12</span></a>), e.g.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></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></span> <span class="GAPinput">SplitString(str, "", "\n");</span>
[ "The quick brown fox", "jumps over the lazy dog." ]
<span class="GAPprompt">gap></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-19 StartsWith</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StartsWith</code>( <var class="Arg">string</var>, <var class="Arg">prefix</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EndsWith</code>( <var class="Arg">string</var>, <var class="Arg">suffix</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Determines whether a string starts or ends with another string.</p>
<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-20 NumbersString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NumbersString</code>( <var class="Arg">s</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">( function )</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></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-21 StringNumbers</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringNumbers</code>( <var class="Arg">l</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">( function )</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.html#X7848A9D878FD59BB"><span class="RefLink">27.7-20</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></span> <span class="GAPinput">StringNumbers(l,1000000);</span>
"TWAS BRILLIG AND THE SLITHY TOVES"
</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">‣ IntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">( function )</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">‣ CharInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">c:=CharInt(65);</span>
'A'
<span class="GAPprompt">gap></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">‣ SIntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">( function )</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">‣ CharSInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">SIntChar(c);</span>
65
<span class="GAPprompt">gap></span> <span class="GAPinput">c:=CharSInt(-20);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">SIntChar(c);</span>
-20
<span class="GAPprompt">gap></span> <span class="GAPinput">IntChar(c);</span>
236
<span class="GAPprompt">gap></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">‣ Int</code>( <var class="Arg">str</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Rat</code>( <var class="Arg">str</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IntHexString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>return either an integer (<code class="func">Int</code> and <code class="func">IntHexString</code>), or a rational (<code class="func">Rat</code>) as represented by the string <var class="Arg">str</var>. <code class="func">Int</code> returns <code class="keyw">fail</code> if non-digit characters occur in <var class="Arg">str</var>. For <code class="func">Rat</code>, the argument string may start with the sign character <code class="code">-</code>, followed by either a sequence of digits or by two sequences of 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. (The methods only evaluate numbers but do <em>not</em> perform arithmetic!)</p>
<p><code class="func">IntHexString</code> evaluates an integer written with hexa-decimal 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>. An error occurs when a wrong character is found in the string. This function can be used (together with <code class="func">HexStringInt</code> (<a href="chap27.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 hexa-decimal representation costs linear computation time in terms of the number of digits, while translation from and into decimal representation needs substantial computations. If <var class="Arg">str</var> is not in compact string representation then <code class="func">ConvertToStringRep</code> (<a href="chap27.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>) is applied to it as side effect.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("12345")+1;</span>
12346
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("123/45");</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("1+2");</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("-12");</span>
-12
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat("123/45");</span>
41/15
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat( "123.45" );</span>
2469/20
<span class="GAPprompt">gap></span> <span class="GAPinput">IntHexString("-abcdef0123456789");</span>
-12379813738877118345
<span class="GAPprompt">gap></span> <span class="GAPinput">HexStringInt(last);</span>
"-ABCDEF0123456789"
</pre></div>
<p><a id="X7C0C29C87CBA97B7" name="X7C0C29C87CBA97B7"></a></p>
<h5>27.9-2 Ordinal</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Ordinal</code>( <var class="Arg">n</var> )</td><td class="tdright">( function )</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></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-3 EvalString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EvalString</code>( <var class="Arg">expr</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">a:=10;</span>
10
<span class="GAPprompt">gap></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.html#X7ABABCDF7ED81F7F"><span class="RefLink">10.7-1</span></a>) and <code class="func">ReadAsFunction</code> (<a href="chap10.html#X7D62F2877F0E45A7"><span class="RefLink">10.3-2</span></a>) together; see <a href="chap10.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></span> <span class="GAPinput">global_a := 0;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">global_b := 0;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">example := function ( local_a )</span>
<span class="GAPprompt">></span> <span class="GAPinput"> local local_b;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> local_b := 5;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> global_a := local_a;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> global_b := local_b;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> return EvalString( "global_a * global_b" );</span>
<span class="GAPprompt">></span> <span class="GAPinput">end;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">example( 2 );</span>
10
</pre></div>
<p><a id="X7D4B9D7A7995C55D" name="X7D4B9D7A7995C55D"></a></p>
<h5>27.9-4 CrcString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CrcString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: an integer</p>
<p>This function computes a cyclic redundancy check number from a string <var class="Arg">str</var>. See also <code class="func">CrcFile</code> (<a href="chap9.html#X8241CEAD80415BB9"><span class="RefLink">9.7-7</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">CrcString("GAP example string");</span>
-50451670
</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">‣ DaysInYear</code>( <var class="Arg">year</var> )</td><td class="tdright">( function )</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">‣ DaysInMonth</code>( <var class="Arg">month</var>, <var class="Arg">year</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">DaysInYear(1998);</span>
365
<span class="GAPprompt">gap></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">‣ DMYDay</code>( <var class="Arg">day</var> )</td><td class="tdright">( function )</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">‣ DayDMY</code>( <var class="Arg">dmy</var> )</td><td class="tdright">( function )</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">‣ WeekDay</code>( <var class="Arg">date</var> )</td><td class="tdright">( function )</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">‣ StringDate</code>( <var class="Arg">date</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">DayDMY([1,1,1970]);DayDMY([2,1,1970]);</span>
0
1
<span class="GAPprompt">gap></span> <span class="GAPinput">DMYDay(12345);</span>
[ 20, 10, 2003 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">WeekDay([11,3,1998]);</span>
"Wed"
<span class="GAPprompt">gap></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">‣ HMSMSec</code>( <var class="Arg">msec</var> )</td><td class="tdright">( function )</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">‣ SecHMSM</code>( <var class="Arg">hmsm</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>is the reverse of <code class="func">HMSMSec</code> (<a href="chap27.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">‣ StringTime</code>( <var class="Arg">time</var> )</td><td class="tdright">( function )</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></span> <span class="GAPinput">HMSMSec(Factorial(10));</span>
[ 1, 0, 28, 800 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SecHMSM([1,10,5,13]);</span>
4205013
<span class="GAPprompt">gap></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">‣ SecondsDMYhms</code>( <var class="Arg">DMYhms</var> )</td><td class="tdright">( function )</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.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">‣ DMYhmsSeconds</code>( <var class="Arg">secs</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This is the inverse function to <code class="func">SecondsDMYhms</code> (<a href="chap27.html#X870A71D47B0E936E"><span class="RefLink">27.10-10</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SecondsDMYhms([ 9, 9, 2001, 1, 46, 40 ]);</span>
1000000000
<span class="GAPprompt">gap></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.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"> <a href="chap0.html">[Top of Book]</a> <a href="chap0.html#contents">[Contents]</a> <a href="chap26.html">[Previous Chapter]</a> <a href="chap28.html">[Next Chapter]</a> </div>
<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a> <a href="chap1.html">1</a> <a href="chap2.html">2</a> <a href="chap3.html">3</a> <a href="chap4.html">4</a> <a href="chap5.html">5</a> <a href="chap6.html">6</a> <a href="chap7.html">7</a> <a href="chap8.html">8</a> <a href="chap9.html">9</a> <a href="chap10.html">10</a> <a href="chap11.html">11</a> <a href="chap12.html">12</a> <a href="chap13.html">13</a> <a href="chap14.html">14</a> <a href="chap15.html">15</a> <a href="chap16.html">16</a> <a href="chap17.html">17</a> <a href="chap18.html">18</a> <a href="chap19.html">19</a> <a href="chap20.html">20</a> <a href="chap21.html">21</a> <a href="chap22.html">22</a> <a href="chap23.html">23</a> <a href="chap24.html">24</a> <a href="chap25.html">25</a> <a href="chap26.html">26</a> <a href="chap27.html">27</a> <a href="chap28.html">28</a> <a href="chap29.html">29</a> <a href="chap30.html">30</a> <a href="chap31.html">31</a> <a href="chap32.html">32</a> <a href="chap33.html">33</a> <a href="chap34.html">34</a> <a href="chap35.html">35</a> <a href="chap36.html">36</a> <a href="chap37.html">37</a> <a href="chap38.html">38</a> <a href="chap39.html">39</a> <a href="chap40.html">40</a> <a href="chap41.html">41</a> <a href="chap42.html">42</a> <a href="chap43.html">43</a> <a href="chap44.html">44</a> <a href="chap45.html">45</a> <a href="chap46.html">46</a> <a href="chap47.html">47</a> <a href="chap48.html">48</a> <a href="chap49.html">49</a> <a href="chap50.html">50</a> <a href="chap51.html">51</a> <a href="chap52.html">52</a> <a href="chap53.html">53</a> <a href="chap54.html">54</a> <a href="chap55.html">55</a> <a href="chap56.html">56</a> <a href="chap57.html">57</a> <a href="chap58.html">58</a> <a href="chap59.html">59</a> <a href="chap60.html">60</a> <a href="chap61.html">61</a> <a href="chap62.html">62</a> <a href="chap63.html">63</a> <a href="chap64.html">64</a> <a href="chap65.html">65</a> <a href="chap66.html">66</a> <a href="chap67.html">67</a> <a href="chap68.html">68</a> <a href="chap69.html">69</a> <a href="chap70.html">70</a> <a href="chap71.html">71</a> <a href="chap72.html">72</a> <a href="chap73.html">73</a> <a href="chap74.html">74</a> <a href="chap75.html">75</a> <a href="chap76.html">76</a> <a href="chap77.html">77</a> <a href="chap78.html">78</a> <a href="chap79.html">79</a> <a href="chap80.html">80</a> <a href="chap81.html">81</a> <a href="chap82.html">82</a> <a href="chap83.html">83</a> <a href="chap84.html">84</a> <a href="chap85.html">85</a> <a href="chap86.html">86</a> <a href="chap87.html">87</a> <a href="chapBib.html">Bib</a> <a href="chapInd.html">Ind</a> </div>
<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>
|