Debian Codegraph @

doc/ref/chap27.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
7 <head>
8 <title>GAP (ref) - Chapter 27: Strings and Characters</title>
9 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
10 <meta name="generator" content="GAPDoc2HTML" />
11 <link rel="stylesheet" type="text/css" href="manual.css" />
12 <script src="manual.js" type="text/javascript"></script>
13 <script type="text/javascript">overwriteStyle();</script>
14 </head>
15 <body class="chap27" onload="jscontent()">
16
17
18 <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>
19
20 <div class="chlinkprevnexttop">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap26.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap28.html">[Next Chapter]</a>&nbsp; </div>
21
22 <p id="mathjaxlink" class="pcenter"><a href="chap27_mj.html">[MathJax on]</a></p>
23 <p><a id="X7D28329B7EDB8F47" name="X7D28329B7EDB8F47"></a></p>
24 <div class="ChapSects"><a href="chap27.html#X7D28329B7EDB8F47">27 <span class="Heading">Strings and Characters</span></a>
25 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X7A90690B78260194">27.1 <span class="Heading">IsChar and IsString</span></a>
26 </span>
27 <div class="ContSSBlock">
28 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X80CFAE128560E064">27.1-1 IsChar</a></span>
29 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X78723B5D795A3B6D">27.1-2 IsString</a></span>
30 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7B1B45C587A72F96">27.1-3 <span class="Heading">Strings As Lists</span></a>
31 </span>
32 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7EA6CA7486D7E9DD">27.1-4 <span class="Heading">Printing Strings</span></a>
33 </span>
34 </div></div>
35 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X82E5F5AB818F32DB">27.2 <span class="Heading">Special Characters</span></a>
36 </span>
37 </div>
38 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X7E70384E7D0B7083">27.3 <span class="Heading">Triple Quoted Strings</span></a>
39 </span>
40 </div>
41 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X82AEC07487C45ECD">27.4 <span class="Heading">Internally Represented Strings</span></a>
42 </span>
43 <div class="ContSSBlock">
44 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7A17EDF8785C9F58">27.4-1 IsStringRep</a></span>
45 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7CE2415F7FEC5809">27.4-2 ConvertToStringRep</a></span>
46 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7FFC464683CC8023">27.4-3 CopyToStringRep</a></span>
47 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7D944D507CBB24CD">27.4-4 IsEmptyString</a></span>
48 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X836078DC829A8221">27.4-5 EmptyString</a></span>
49 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7DA671FC7F490C16">27.4-6 CharsFamily</a></span>
50 </div></div>
51 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X82F980A17FE84AA4">27.5 <span class="Heading">Recognizing Characters</span></a>
52 </span>
53 <div class="ContSSBlock">
54 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X78566FD57B95ECBE">27.5-1 IsDigitChar</a></span>
55 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X854114A97BAFEAEA">27.5-2 IsLowerAlphaChar</a></span>
56 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87B1A13D81353AD8">27.5-3 IsUpperAlphaChar</a></span>
57 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X84634DF67A431D26">27.5-4 IsAlphaChar</a></span>
58 </div></div>
59 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X8127954B79B8A0DA">27.6 <span class="Heading">Comparisons of Strings</span></a>
60 </span>
61 <div class="ContSSBlock">
62 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X79538F138286739A"><code>27.6-1 \=</code></a></span>
63 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8129E3A785F60093"><code>27.6-2 \&lt;</code></a></span>
64 </div></div>
65 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X7E72717A82A309F5">27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></a>
66 </span>
67 <div class="ContSSBlock">
68 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X792FB3A1849FD739">27.7-1 DisplayString</a></span>
69 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8482132779EA7A23">27.7-2 DEFAULTDISPLAYSTRING</a></span>
70 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7803FBCA79DB5529">27.7-3 ViewString</a></span>
71 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7BBDF9D383595425">27.7-4 DEFAULTVIEWSTRING</a></span>
72 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7B3CC87285DEC23D">27.7-5 PrintString</a></span>
73 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X81FB5BE27903EC32">27.7-6 String</a></span>
74 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X86AACCE987F74FA5">27.7-7 StripLineBreakCharacters</a></span>
75 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X865FBB7E788017DD">27.7-8 HexStringInt</a></span>
76 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7BB1059185AB4F84">27.7-9 StringPP</a></span>
77 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X79C8280A853D8FA9">27.7-10 WordAlp</a></span>
78 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X798A0F35852ABDAD">27.7-11 LowercaseString</a></span>
79 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87A2F2557DE7EE08">27.7-12 LowercaseChar</a></span>
80 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7E7E5F5B7FED56A0">27.7-13 UppercaseString</a></span>
81 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X81E0AEE687200505">27.7-14 UppercaseChar</a></span>
82 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X86E897D486DCFEAB">27.7-15 SplitString</a></span>
83 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X864F0A9078D4DE0E">27.7-16 ReplacedString</a></span>
84 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X806379367A53D171">27.7-17 NormalizeWhitespace</a></span>
85 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8685DE9386E57771">27.7-18 NormalizedWhitespace</a></span>
86 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X86EBB6EB829723E4">27.7-19 RemoveCharacters</a></span>
87 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X84624FEB825EC4B5">27.7-20 JoinStringsWithSeparator</a></span>
88 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X79F8FFC5876D854A">27.7-21 Chomp</a></span>
89 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X855820848179CC28">27.7-22 StartsWith</a></span>
90 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8235AD797868E872">27.7-23 StringFormatted</a></span>
91 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7848A9D878FD59BB">27.7-24 NumbersString</a></span>
92 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X787EAB117816578E">27.7-25 StringNumbers</a></span>
93 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X82975B6480932683">27.7-26 StringOfMemoryAmount</a></span>
94 </div></div>
95 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X844BDC8578A3B508">27.8 <span class="Heading">Character Conversion</span></a>
96 </span>
97 <div class="ContSSBlock">
98 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X826D95D680F87D23">27.8-1 IntChar</a></span>
99 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87B6C1AF7E4A6639">27.8-2 CharInt</a></span>
100 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8159CE81798DDA76">27.8-3 SIntChar</a></span>
101 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X78E6611A829DDA3E">27.8-4 CharSInt</a></span>
102 </div></div>
103 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X78D9BD857F890C0A">27.9 <span class="Heading">Operations to Evaluate Strings</span></a>
104 </span>
105 <div class="ContSSBlock">
106 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7B6D118184F692A0">27.9-1 Int</a></span>
107 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87AD395584294FF2">27.9-2 Rat</a></span>
108 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X796D366B7DDEFF67">27.9-3 IntHexString</a></span>
109 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7C0C29C87CBA97B7">27.9-4 Ordinal</a></span>
110 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7DE4CCD285440659">27.9-5 EvalString</a></span>
111 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7D4B9D7A7995C55D">27.9-6 CrcString</a></span>
112 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7873D1F28779B490">27.9-7 HexSHA256</a></span>
113 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X83FF17E782E6FFF3">27.9-8 Pluralize</a></span>
114 </div></div>
115 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X78F20AA1804D524F">27.10 <span class="Heading">Calendar Arithmetic</span></a>
116 </span>
117 <div class="ContSSBlock">
118 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87BA46787FF000E8">27.10-1 DaysInYear</a></span>
119 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X8791B0B386D59ADB">27.10-2 DaysInMonth</a></span>
120 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7CED84C07CD5E2CF">27.10-3 DMYDay</a></span>
121 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7A79DEE07A41B8EF">27.10-4 DayDMY</a></span>
122 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X87D03FC0809DB6EC">27.10-5 WeekDay</a></span>
123 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X7C74C33784CDED6C">27.10-6 StringDate</a></span>
124 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X84A6A2637FB35A32">27.10-7 HMSMSec</a></span>
125 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X879461D77C81100B">27.10-8 SecHMSM</a></span>
126 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X802469C47F886A59">27.10-9 StringTime</a></span>
127 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X870A71D47B0E936E">27.10-10 SecondsDMYhms</a></span>
128 <span class="ContSS"><br /><span class="nocss">&nbsp;&nbsp;</span><a href="chap27.html#X78AF8EA887532B5B">27.10-11 DMYhmsSeconds</a></span>
129 </div></div>
130 <div class="ContSect"><span class="tocline"><span class="nocss">&nbsp;</span><a href="chap27.html#X78024C8087F3E07F">27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></a>
131 </span>
132 </div>
133 </div>
134
135 <h3>27 <span class="Heading">Strings and Characters</span></h3>
136
137 <p><a id="X7A90690B78260194" name="X7A90690B78260194"></a></p>
138
139 <h4>27.1 <span class="Heading">IsChar and IsString</span></h4>
140
141 <p><a id="X80CFAE128560E064" name="X80CFAE128560E064"></a></p>
142
143 <h5>27.1-1 IsChar</h5>
144
145 <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>
146 <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>
147 <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>
148
149
150 <div class="example"><pre>
151 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">x:= 'a'; IsChar( x );</span>
152 'a'
153 true
154 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">'*';</span>
155 '*'
156 </pre></div>
157
158 <p><a id="X78723B5D795A3B6D" name="X78723B5D795A3B6D"></a></p>
159
160 <h5>27.1-2 IsString</h5>
161
162 <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>
163 <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>
164
165 <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>
166
167 <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.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>.</p>
168
169
170 <div class="example"><pre>
171 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1 := ['H','e','l','l','o',' ','w','o','r','l','d','.'];</span>
172 "Hello world."
173 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( s1 );</span>
174 true
175 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2 := "Hello world.";</span>
176 "Hello world."
177 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1 = s2;</span>
178 true
179 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s3 := ""; # the empty string</span>
180 ""
181 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s3 = [];</span>
182 true
183 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [] );</span>
184 true
185 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( "123" ); IsString( 123 );</span>
186 true
187 false
188 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', '3' ] );</span>
189 true
190 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', , '4' ] ); # strings must be dense</span>
191 false
192 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsString( [ '1', '2', 3 ] ); # strings must only contain characters</span>
193 false
194 </pre></div>
195
196 <p><a id="X7B1B45C587A72F96" name="X7B1B45C587A72F96"></a></p>
197
198 <h5>27.1-3 <span class="Heading">Strings As Lists</span></h5>
199
200 <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>
201
202
203 <div class="example"><pre>
204 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Length( s2 );</span>
205 12
206 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2[2];</span>
207 'e'
208 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">'a' in s2;</span>
209 false
210 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s2[2] := 'a';; s2;</span>
211 "Hallo world."
212 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1{ [1..4] };</span>
213 "Hell"
214 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Concatenation( s1{ [ 1 .. 6 ] }, s1{ [ 1 .. 4 ] } );</span>
215 "Hello Hell"
216 </pre></div>
217
218 <p><a id="X7EA6CA7486D7E9DD" name="X7EA6CA7486D7E9DD"></a></p>
219
220 <h5>27.1-4 <span class="Heading">Printing Strings</span></h5>
221
222 <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>
223 <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>
224 <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>
225
226 <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.8-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9.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>
227
228
229 <div class="example"><pre>
230 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s4:= "abc\"def\nghi";;</span>
231 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">View( s4 ); Print( "\n" );</span>
232 "abc\"def\nghi"
233 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ViewObj( s4 ); Print( "\n" );</span>
234 "abc\"def\nghi"
235 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintObj( s4 ); Print( "\n" );</span>
236 "abc\"def\nghi"
237 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s4 ); Print( "\n" );</span>
238 abc"def
239 ghi
240 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "German uses strange characters: äöüß\n";</span>
241 "German uses strange characters: äöüß\n"
242 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(s);</span>
243 German uses strange characters: äöüß
244 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintObj(s); Print( "\n" );</span>
245 "German uses strange characters: \303\244\303\266\303\274\303\237\n"
246 </pre></div>
247
248
249 <div class="example"><pre>
250 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "\007";</span>
251 "\007"
252 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(s); # rings bell in many terminals</span>
253 </pre></div>
254
255 <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>
256
257
258 <div class="example"><pre>
259 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s1;</span>
260 "Hello world."
261 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s1 );</span>
262 Hello world.gap&gt; Print( s1, "\n" );
263 Hello world.
264 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( s1, "\nnext line\n" );</span>
265 Hello world.
266 next line
267 </pre></div>
268
269 <p><a id="X82E5F5AB818F32DB" name="X82E5F5AB818F32DB"></a></p>
270
271 <h4>27.2 <span class="Heading">Special Characters</span></h4>
272
273 <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>
274
275
276 <dl>
277 <dt><strong class="Mark">
278
279
280 <code class="code">\n</code></strong></dt>
281 <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>
282
283 </dd>
284 <dt><strong class="Mark">
285
286
287 <code class="code">\"</code></strong></dt>
288 <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>
289
290 </dd>
291 <dt><strong class="Mark">
292
293
294 <code class="code">\'</code></strong></dt>
295 <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>
296
297 </dd>
298 <dt><strong class="Mark">
299
300
301 <code class="code">\\</code></strong></dt>
302 <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>
303
304 </dd>
305 <dt><strong class="Mark">
306
307
308 <code class="code">\b</code></strong></dt>
309 <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>
310
311 </dd>
312 <dt><strong class="Mark">
313
314
315 <code class="code">\r</code></strong></dt>
316 <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>
317
318 </dd>
319 <dt><strong class="Mark">
320
321
322 <code class="code">\c</code></strong></dt>
323 <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>
324
325 </dd>
326 <dt><strong class="Mark">
327
328
329 <code class="code">\XYZ</code></strong></dt>
330 <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>
331
332 </dd>
333 <dt><strong class="Mark">
334
335
336 <code class="code">\0xYZ</code></strong></dt>
337 <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>
338
339 </dd>
340 <dt><strong class="Mark">
341
342 other</strong></dt>
343 <dd><p>For any other character the backslash is ignored.</p>
344
345 </dd>
346 </dl>
347 <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>
348
349 <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.8-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>) send the characters directly to the output stream.</p>
350
351
352 <div class="example"><pre>
353 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"This is one line.\nThis is another line.\n";</span>
354 "This is one line.\nThis is another line.\n"
355 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( last );</span>
356 This is one line.
357 This is another line.
358 </pre></div>
359
360 <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>
361
362 <p><a id="X7E70384E7D0B7083" name="X7E70384E7D0B7083"></a></p>
363
364 <h4>27.3 <span class="Heading">Triple Quoted Strings</span></h4>
365
366 <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>
367
368
369 <div class="example"><pre>
370 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"""Print("\n")""";</span>
371 "Print(\"\\n\")"
372 </pre></div>
373
374 <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&gt; </code>, <code class="code">&gt; </code> or <code class="code">brk&gt; </code> will have this beginning part removed.</p>
375
376 <p><a id="X82AEC07487C45ECD" name="X82AEC07487C45ECD"></a></p>
377
378 <h4>27.4 <span class="Heading">Internally Represented Strings</span></h4>
379
380 <p><a id="X7A17EDF8785C9F58" name="X7A17EDF8785C9F58"></a></p>
381
382 <h5>27.4-1 IsStringRep</h5>
383
384 <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>
385 <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>
386
387 <p><a id="X7CE2415F7FEC5809" name="X7CE2415F7FEC5809"></a></p>
388
389 <h5>27.4-2 ConvertToStringRep</h5>
390
391 <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>
392 <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="func">IsPlistRep</code> (<a href="chap21.html#X87BA4EBF80F16B72"><span class="RefLink">21.24-2</span></a>), 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>
393
394 <p><a id="X7FFC464683CC8023" name="X7FFC464683CC8023"></a></p>
395
396 <h5>27.4-3 CopyToStringRep</h5>
397
398 <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>
399 <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>
400
401 <p><a id="X7D944D507CBB24CD" name="X7D944D507CBB24CD"></a></p>
402
403 <h5>27.4-4 IsEmptyString</h5>
404
405 <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>
406 <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>
407
408
409 <div class="example"><pre>
410 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l:= [];; IsString( l ); IsEmptyString( l ); IsEmpty( l );</span>
411 true
412 false
413 true
414 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l; ConvertToStringRep( l ); l;</span>
415 [ ]
416 ""
417 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IsEmptyString( l ); IsEmptyString( "" ); IsEmptyString( "abc" );</span>
418 true
419 true
420 false
421 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ll:= [ 'a', 'b' ]; IsStringRep( ll ); ConvertToStringRep( ll );</span>
422 "ab"
423 false
424 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ll; IsStringRep( ll );</span>
425 "ab"
426 true
427 </pre></div>
428
429 <p><a id="X836078DC829A8221" name="X836078DC829A8221"></a></p>
430
431 <h5>27.4-5 EmptyString</h5>
432
433 <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>
434 <p>Returns: a string</p>
435
436 <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>
437 <p>Returns: nothing</p>
438
439 <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>
440
441 <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>
442
443 <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.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>
444
445 <p><a id="X7DA671FC7F490C16" name="X7DA671FC7F490C16"></a></p>
446
447 <h5>27.4-6 CharsFamily</h5>
448
449 <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>
450 <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>
451
452 <p><a id="X82F980A17FE84AA4" name="X82F980A17FE84AA4"></a></p>
453
454 <h4>27.5 <span class="Heading">Recognizing Characters</span></h4>
455
456 <p><a id="X78566FD57B95ECBE" name="X78566FD57B95ECBE"></a></p>
457
458 <h5>27.5-1 IsDigitChar</h5>
459
460 <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>
461 <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>
462
463 <p><a id="X854114A97BAFEAEA" name="X854114A97BAFEAEA"></a></p>
464
465 <h5>27.5-2 IsLowerAlphaChar</h5>
466
467 <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>
468 <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>
469
470 <p><a id="X87B1A13D81353AD8" name="X87B1A13D81353AD8"></a></p>
471
472 <h5>27.5-3 IsUpperAlphaChar</h5>
473
474 <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>
475 <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>
476
477 <p><a id="X84634DF67A431D26" name="X84634DF67A431D26"></a></p>
478
479 <h5>27.5-4 IsAlphaChar</h5>
480
481 <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>
482 <p>checks whether the character <var class="Arg">c</var> is either a lowercase or an uppercase alphabet letter.</p>
483
484 <p><a id="X8127954B79B8A0DA" name="X8127954B79B8A0DA"></a></p>
485
486 <h4>27.6 <span class="Heading">Comparisons of Strings</span></h4>
487
488 <p><a id="X79538F138286739A" name="X79538F138286739A"></a></p>
489
490 <h5><code>27.6-1 \=</code></h5>
491
492 <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>
493 <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>
494
495
496 <div class="example"><pre>
497 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world.\n" = "Hello world.\n";</span>
498 true
499 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello World.\n" = "Hello world.\n"; # comparison is case sensitive</span>
500 false
501 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world." = "Hello world.\n"; # first string has no &lt;newline&gt;</span>
502 false
503 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Goodbye world.\n" = "Hello world.\n";</span>
504 false
505 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">[ 'a', 'b' ] = "ab";</span>
506 true
507 </pre></div>
508
509 <p><a id="X8129E3A785F60093" name="X8129E3A785F60093"></a></p>
510
511 <h5><code>27.6-2 \&lt;</code></h5>
512
513 <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>
514 <p>The ordering of strings is lexicographically according to the order implied by the underlying, system dependent, character set.</p>
515
516
517 <div class="example"><pre>
518 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world.\n" &lt; "Hello world.\n"; # the strings are equal</span>
519 false
520 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># in ASCII capitals range before small letters:</span>
521 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello World." &lt; "Hello world.";</span>
522 true
523 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Hello world." &lt; "Hello world.\n"; # prefixes are always smaller</span>
524 true
525 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput"># G comes before H, in ASCII at least:</span>
526 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">"Goodbye world.\n" &lt; "Hello world.\n";</span>
527 true
528 </pre></div>
529
530 <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.html#X7A274A1F8553B7E6"><span class="RefLink">4.13</span></a> for the details.</p>
531
532 <p><a id="X7E72717A82A309F5" name="X7E72717A82A309F5"></a></p>
533
534 <h4>27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></h4>
535
536 <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>
537
538 <p><a id="X792FB3A1849FD739" name="X792FB3A1849FD739"></a></p>
539
540 <h5>27.7-1 DisplayString</h5>
541
542 <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>
543 <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>
544
545 <p><a id="X8482132779EA7A23" name="X8482132779EA7A23"></a></p>
546
547 <h5>27.7-2 DEFAULTDISPLAYSTRING</h5>
548
549 <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>
550 <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>
551
552 <p><a id="X7803FBCA79DB5529" name="X7803FBCA79DB5529"></a></p>
553
554 <h5>27.7-3 ViewString</h5>
555
556 <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>
557 <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>
558
559 <p><a id="X7BBDF9D383595425" name="X7BBDF9D383595425"></a></p>
560
561 <h5>27.7-4 DEFAULTVIEWSTRING</h5>
562
563 <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>
564 <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>
565
566 <p><a id="X7B3CC87285DEC23D" name="X7B3CC87285DEC23D"></a></p>
567
568 <h5>27.7-5 PrintString</h5>
569
570 <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>
571 <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>
572
573 <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>
574
575 <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>
576
577
578 <div class="example"><pre>
579 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">PrintString(123);PrintString([1,2,3]);</span>
580 "123"
581 "[ 1, 2, 3 ]"
582 </pre></div>
583
584 <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.html#X86AACCE987F74FA5"><span class="RefLink">27.7-7</span></a>) for a function to get rid of these control characters.</p>
585
586 <p><a id="X81FB5BE27903EC32" name="X81FB5BE27903EC32"></a></p>
587
588 <h5>27.7-6 String</h5>
589
590 <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>
591 <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>
592
593 <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>
594
595 <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>
596
597
598 <div class="example"><pre>
599 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">String(123);String([1,2,3]);</span>
600 "123"
601 "[ 1, 2, 3 ]"
602 </pre></div>
603
604 <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>
605
606 <p><a id="X86AACCE987F74FA5" name="X86AACCE987F74FA5"></a></p>
607
608 <h5>27.7-7 StripLineBreakCharacters</h5>
609
610 <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>
611 <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.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>
612
613 <p><a id="X865FBB7E788017DD" name="X865FBB7E788017DD"></a></p>
614
615 <h5>27.7-8 HexStringInt</h5>
616
617 <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>
618 <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.html#X796D366B7DDEFF67"><span class="RefLink">27.9-3</span></a>).</p>
619
620 <p><a id="X7BB1059185AB4F84" name="X7BB1059185AB4F84"></a></p>
621
622 <h5>27.7-9 StringPP</h5>
623
624 <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>
625 <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.html#X803D431087B6FF28"><span class="RefLink">14.4-10</span></a>).</p>
626
627
628 <div class="example"><pre>
629 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringPP(40320);</span>
630 "2^7*3^2*5*7"
631 </pre></div>
632
633 <p><a id="X79C8280A853D8FA9" name="X79C8280A853D8FA9"></a></p>
634
635 <h5>27.7-10 WordAlp</h5>
636
637 <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>
638 <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>
639
640
641 <div class="example"><pre>
642 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">List([0..5],i-&gt;WordAlp("abc",i));</span>
643 [ "", "a", "b", "c", "aa", "ab" ]
644 </pre></div>
645
646 <p><a id="X798A0F35852ABDAD" name="X798A0F35852ABDAD"></a></p>
647
648 <h5>27.7-11 LowercaseString</h5>
649
650 <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>
651 <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>
652
653
654 <div class="example"><pre>
655 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">LowercaseString("This Is UpperCase");</span>
656 "this is uppercase"
657 </pre></div>
658
659 <p><a id="X87A2F2557DE7EE08" name="X87A2F2557DE7EE08"></a></p>
660
661 <h5>27.7-12 LowercaseChar</h5>
662
663 <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>
664 <p>Returns the lowercase version of the character <var class="Arg">character</var>.</p>
665
666 <p><a id="X7E7E5F5B7FED56A0" name="X7E7E5F5B7FED56A0"></a></p>
667
668 <h5>27.7-13 UppercaseString</h5>
669
670 <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>
671 <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>
672
673
674 <div class="example"><pre>
675 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">UppercaseString("This Is UpperCase");</span>
676 "THIS IS UPPERCASE"
677 </pre></div>
678
679 <p><a id="X81E0AEE687200505" name="X81E0AEE687200505"></a></p>
680
681 <h5>27.7-14 UppercaseChar</h5>
682
683 <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>
684 <p>Returns the uppercase version of the character <var class="Arg">character</var>.</p>
685
686 <p><a id="X86E897D486DCFEAB" name="X86E897D486DCFEAB"></a></p>
687
688 <h5>27.7-15 SplitString</h5>
689
690 <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>
691 <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>
692
693 <p>Both arguments <var class="Arg">seps</var> and <var class="Arg">wspace</var> can be single characters.</p>
694
695 <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>
696
697 <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>
698
699 <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-21</span></a>).</p>
700
701
702 <div class="example"><pre>
703 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "substr1:substr2::substr4", ":" );</span>
704 [ "substr1", "substr2", "", "substr4" ]
705 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "a;b;c;d;", ";" );</span>
706 [ "a", "b", "c", "d" ]
707 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString( "/home//user//dir/", "", "/" );</span>
708 [ "home", "user", "dir" ]
709 </pre></div>
710
711 <p><a id="X864F0A9078D4DE0E" name="X864F0A9078D4DE0E"></a></p>
712
713 <h5>27.7-16 ReplacedString</h5>
714
715 <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>
716 <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>
717
718
719 <div class="example"><pre>
720 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("abacab","a","zl");</span>
721 "zlbzlczlb"
722 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("ababa", "aba","c");</span>
723 "cba"
724 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">ReplacedString("abacab","a","ba");</span>
725 "babbacbab"
726 </pre></div>
727
728 <p><a id="X806379367A53D171" name="X806379367A53D171"></a></p>
729
730 <h5>27.7-17 NormalizeWhitespace</h5>
731
732 <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>
733 <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>
734
735 <p>See <code class="func">NormalizedWhitespace</code> (<a href="chap27.html#X8685DE9386E57771"><span class="RefLink">27.7-18</span></a>) for a non-destructive version.</p>
736
737
738 <div class="example"><pre>
739 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := " x y \n\n\t\r z\n \n";</span>
740 " x y \n\n\t\r z\n \n"
741 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">NormalizeWhitespace(s);</span>
742 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s;</span>
743 "x y z"
744 </pre></div>
745
746 <p><a id="X8685DE9386E57771" name="X8685DE9386E57771"></a></p>
747
748 <h5>27.7-18 NormalizedWhitespace</h5>
749
750 <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>
751 <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-17</span></a>) was applied.</p>
752
753 <p><a id="X86EBB6EB829723E4" name="X86EBB6EB829723E4"></a></p>
754
755 <h5>27.7-19 RemoveCharacters</h5>
756
757 <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>
758 <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>
759
760
761 <div class="example"><pre>
762 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s := "ab c\ndef\n\ng h i .\n";</span>
763 "ab c\ndef\n\ng h i .\n"
764 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">RemoveCharacters(s, " \n\t\r"); # remove all whitespace characters</span>
765 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">s;</span>
766 "abcdefghi."
767 </pre></div>
768
769 <p><a id="X84624FEB825EC4B5" name="X84624FEB825EC4B5"></a></p>
770
771 <h5>27.7-20 JoinStringsWithSeparator</h5>
772
773 <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>
774 <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>
775
776
777 <div class="example"><pre>
778 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">list := List([1..10], String);</span>
779 [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
780 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">JoinStringsWithSeparator(list);</span>
781 "1,2,3,4,5,6,7,8,9,10"
782 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">JoinStringsWithSeparator(["The", "quick", "brown", "fox"], " ");</span>
783 "The quick brown fox"
784 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">new:= JoinStringsWithSeparator(["a", "b", "c", "d"], ",\n ");</span>
785 "a,\n b,\n c,\n d"
786 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print(" ", new, "\n");</span>
787 a,
788 b,
789 c,
790 d
791 </pre></div>
792
793 <p><a id="X79F8FFC5876D854A" name="X79F8FFC5876D854A"></a></p>
794
795 <h5>27.7-21 Chomp</h5>
796
797 <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>
798 <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>
799
800
801 <div class="example"><pre>
802 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\n");</span>
803 "The quick brown fox jumps over the lazy dog."
804 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\r\n");</span>
805 "The quick brown fox jumps over the lazy dog."
806 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.");</span>
807 "The quick brown fox jumps over the lazy dog."
808 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(fail);</span>
809 fail
810 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(32);</span>
811 32
812 </pre></div>
813
814 <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-15</span></a>), e.g.</p>
815
816
817 <div class="example"><pre>
818 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">str := "The quick brown fox\njumps over the lazy dog.\n";</span>
819 "The quick brown fox\njumps over the lazy dog.\n"
820 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SplitString(str, "", "\n");</span>
821 [ "The quick brown fox", "jumps over the lazy dog." ]
822 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Chomp(str);</span>
823 "The quick brown fox\njumps over the lazy dog."
824 </pre></div>
825
826 <p><a id="X855820848179CC28" name="X855820848179CC28"></a></p>
827
828 <h5>27.7-22 StartsWith</h5>
829
830 <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>
831 <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>
832 <p>Determines whether a string starts or ends with another string.</p>
833
834 <p><a id="X8235AD797868E872" name="X8235AD797868E872"></a></p>
835
836 <h5>27.7-23 StringFormatted</h5>
837
838 <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>
839 <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>
840 <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>
841 <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>
842
843 <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>
844
845 <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>
846
847 <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>
848
849 <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>
850
851 <p><code class="code">id</code> is interpreted as follows:</p>
852
853
854 <dl>
855 <dt><strong class="Mark">An integer <code class="code">i</code></strong></dt>
856 <dd><p>Take the <code class="code">i</code>th element of <var class="Arg">data</var>.</p>
857
858 </dd>
859 <dt><strong class="Mark">A string <code class="code">str</code></strong></dt>
860 <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>
861
862 </dd>
863 <dt><strong class="Mark">No id given</strong></dt>
864 <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>
865
866 </dd>
867 </dl>
868 <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>
869
870 <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.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.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.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>
871
872
873 <div class="example"><pre>
874 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {} cats and {} dogs", 4, 5);</span>
875 "I have 4 cats and 5 dogs"
876 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {2} cats and {1} dogs", 4, 5);</span>
877 "I have 5 cats and 4 dogs"
878 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("I have {cats} cats and {dogs} dogs", rec(cats:=3, dogs:=2));</span>
879 "I have 3 cats and 2 dogs"
880 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("We use {{ and }} to mark {dogs} dogs", rec(cats:=3, dogs:=2));</span>
881 "We use { and } to mark 2 dogs"
882 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">sym3 := SymmetricGroup(3);;</span>
883 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringFormatted("String: {1!s}, ViewString: {1!v}", sym3);</span>
884 "String: SymmetricGroup( [ 1 .. 3 ] ), ViewString: Sym( [ 1 .. 3 ] )"
885 </pre></div>
886
887 <p>The following two functions convert basic strings to lists of numbers and vice versa. They are useful for examples of text encryption.</p>
888
889 <p><a id="X7848A9D878FD59BB" name="X7848A9D878FD59BB"></a></p>
890
891 <h5>27.7-24 NumbersString</h5>
892
893 <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>
894 <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>
895
896
897 <div class="example"><pre>
898 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">l:=NumbersString("Twas brillig and the slithy toves",1000000);</span>
899 [ 303311, 291012, 281922, 221917, 101124, 141030, 181510, 292219,
900 301835, 103025, 321529 ]
901 </pre></div>
902
903 <p><a id="X787EAB117816578E" name="X787EAB117816578E"></a></p>
904
905 <h5>27.7-25 StringNumbers</h5>
906
907 <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>
908 <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-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>
909
910
911 <div class="example"><pre>
912 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringNumbers(l,1000000);</span>
913 "TWAS BRILLIG AND THE SLITHY TOVES"
914 </pre></div>
915
916 <p><a id="X82975B6480932683" name="X82975B6480932683"></a></p>
917
918 <h5>27.7-26 StringOfMemoryAmount</h5>
919
920 <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>
921 <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>
922
923
924 <div class="example"><pre>
925 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringOfMemoryAmount(123456789);</span>
926 "117MB"
927 </pre></div>
928
929 <p><a id="X844BDC8578A3B508" name="X844BDC8578A3B508"></a></p>
930
931 <h4>27.8 <span class="Heading">Character Conversion</span></h4>
932
933 <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>
934
935 <p><a id="X826D95D680F87D23" name="X826D95D680F87D23"></a></p>
936
937 <h5>27.8-1 IntChar</h5>
938
939 <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>
940 <p>returns an integer value in the range <code class="code">[ 0 .. 255 ]</code> that corresponds to <var class="Arg">char</var>.</p>
941
942 <p><a id="X87B6C1AF7E4A6639" name="X87B6C1AF7E4A6639"></a></p>
943
944 <h5>27.8-2 CharInt</h5>
945
946 <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>
947 <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>
948
949
950 <div class="example"><pre>
951 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">c:=CharInt(65);</span>
952 'A'
953 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntChar(c);</span>
954 65
955 </pre></div>
956
957 <p><a id="X8159CE81798DDA76" name="X8159CE81798DDA76"></a></p>
958
959 <h5>27.8-3 SIntChar</h5>
960
961 <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>
962 <p>returns a signed integer value in the range <code class="code">[ -128 .. 127 ]</code> that corresponds to <var class="Arg">char</var>.</p>
963
964 <p><a id="X78E6611A829DDA3E" name="X78E6611A829DDA3E"></a></p>
965
966 <h5>27.8-4 CharSInt</h5>
967
968 <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>
969 <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>
970
971 <p>The signed and unsigned integer functions behave the same for values in the range <code class="code">[ 0 .. 127 ]</code>.</p>
972
973
974 <div class="example"><pre>
975 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(c);</span>
976 65
977 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">c:=CharSInt(-20);;</span>
978 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(c);</span>
979 -20
980 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntChar(c);</span>
981 236
982 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SIntChar(CharInt(255));</span>
983 -1
984 </pre></div>
985
986 <p><a id="X78D9BD857F890C0A" name="X78D9BD857F890C0A"></a></p>
987
988 <h4>27.9 <span class="Heading">Operations to Evaluate Strings</span></h4>
989
990 <p><a id="X7B6D118184F692A0" name="X7B6D118184F692A0"></a></p>
991
992 <h5>27.9-1 Int</h5>
993
994 <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>
995 <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>
996
997 <p>For backwards compatibility, the empty string is accepted, in which case <span class="SimpleMath">0</span> is returned as result.</p>
998
999
1000 <div class="example"><pre>
1001 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("12345");</span>
1002 12345
1003 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("123/45");</span>
1004 fail
1005 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("1+2");</span>
1006 fail
1007 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("-12");</span>
1008 -12
1009 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Int("");</span>
1010 0
1011 </pre></div>
1012
1013 <p><a id="X87AD395584294FF2" name="X87AD395584294FF2"></a></p>
1014
1015 <h5>27.9-2 Rat</h5>
1016
1017 <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>
1018 <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>
1019
1020
1021 <div class="example"><pre>
1022 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat("123/45");</span>
1023 41/15
1024 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Rat("-123.45");</span>
1025 -2469/20
1026 </pre></div>
1027
1028 <p><a id="X796D366B7DDEFF67" name="X796D366B7DDEFF67"></a></p>
1029
1030 <h5>27.9-3 IntHexString</h5>
1031
1032 <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>
1033 <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>
1034
1035 <p>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 hexadecimal representation costs linear computation time in terms of the number of digits, while translation from and into decimal representation needs substantial computations.</p>
1036
1037
1038 <div class="example"><pre>
1039 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">IntHexString("-abcdef0123456789");</span>
1040 -12379813738877118345
1041 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexStringInt(last);</span>
1042 "-ABCDEF0123456789"
1043 </pre></div>
1044
1045 <p><a id="X7C0C29C87CBA97B7" name="X7C0C29C87CBA97B7"></a></p>
1046
1047 <h5>27.9-4 Ordinal</h5>
1048
1049 <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>
1050 <p>returns the ordinal of the integer <var class="Arg">n</var> as a string.</p>
1051
1052
1053 <div class="example"><pre>
1054 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Ordinal(2); Ordinal(21); Ordinal(33); Ordinal(-33);</span>
1055 "2nd"
1056 "21st"
1057 "33rd"
1058 "-33rd"
1059 </pre></div>
1060
1061 <p><a id="X7DE4CCD285440659" name="X7DE4CCD285440659"></a></p>
1062
1063 <h5>27.9-5 EvalString</h5>
1064
1065 <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>
1066 <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>
1067
1068
1069 <div class="example"><pre>
1070 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">a:=10;</span>
1071 10
1072 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">EvalString("a^2");</span>
1073 100
1074 </pre></div>
1075
1076 <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>
1077
1078 <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>
1079
1080
1081 <div class="example"><pre>
1082 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">global_a := 0;;</span>
1083 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">global_b := 0;;</span>
1084 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">example := function ( local_a )</span>
1085 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> local local_b;</span>
1086 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> local_b := 5;</span>
1087 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> global_a := local_a;</span>
1088 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> global_b := local_b;</span>
1089 <span class="GAPprompt">&gt;</span> <span class="GAPinput"> return EvalString( "global_a * global_b" );</span>
1090 <span class="GAPprompt">&gt;</span> <span class="GAPinput">end;;</span>
1091 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">example( 2 );</span>
1092 10
1093 </pre></div>
1094
1095 <p><a id="X7D4B9D7A7995C55D" name="X7D4B9D7A7995C55D"></a></p>
1096
1097 <h5>27.9-6 CrcString</h5>
1098
1099 <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>
1100 <p>Returns: an integer</p>
1101
1102 <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.html#X8241CEAD80415BB9"><span class="RefLink">9.8-7</span></a>) and <code class="func">HexSHA256</code> (<a href="chap27.html#X7873D1F28779B490"><span class="RefLink">27.9-7</span></a>).</p>
1103
1104
1105 <div class="example"><pre>
1106 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">CrcString("GAP example string");</span>
1107 -50451670
1108 </pre></div>
1109
1110 <p><a id="X7873D1F28779B490" name="X7873D1F28779B490"></a></p>
1111
1112 <h5>27.9-7 HexSHA256</h5>
1113
1114 <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>
1115 <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>
1116 <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.html#X839725177BF8B5B4"><span class="RefLink">10</span></a> to learn about streams) when read from the current position until EOF (end-of-file).</p>
1117
1118 <p>The checksum is returned as string with 64 lowercase hexadecimal digits.</p>
1119
1120
1121 <div class="example"><pre>
1122 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexSHA256("abcd");</span>
1123 "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"
1124 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HexSHA256(InputTextString("abcd"));</span>
1125 "88d4266fd4e6338d13b845fcf289579d209c897823b9217da3e161936f031589"
1126 </pre></div>
1127
1128 <p><a id="X83FF17E782E6FFF3" name="X83FF17E782E6FFF3"></a></p>
1129
1130 <h5>27.9-8 Pluralize</h5>
1131
1132 <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>
1133 <p>Returns: A string</p>
1134
1135 <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>
1136
1137 <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>
1138
1139 <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>
1140
1141 <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 ≠ 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>
1142
1143 <p>Note that <code class="func">StripLineBreakCharacters</code> (<a href="chap27.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>
1144
1145
1146 <div class="example"><pre>
1147 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( "generator" );</span>
1148 "generators"
1149 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 1, "generator" );</span>
1150 "\&gt;1\&lt; generator"
1151 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 0, "generator" );</span>
1152 "\&gt;0\&lt; generators"
1153 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( "man", "men" );</span>
1154 "men"
1155 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Pluralize( 1, "man", "men" );</span>
1156 "\&gt;1\&lt; man"
1157 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 2, "man", "men" ) );</span>
1158 2 men
1159 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 2, "vertex" ) );</span>
1160 2 vertices
1161 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 3, "matrix" ) );</span>
1162 3 matrices
1163 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">Print( Pluralize( 4, "battery" ) );</span>
1164 4 batteries
1165 </pre></div>
1166
1167 <p><a id="X78F20AA1804D524F" name="X78F20AA1804D524F"></a></p>
1168
1169 <h4>27.10 <span class="Heading">Calendar Arithmetic</span></h4>
1170
1171 <p>All calendar functions use the Gregorian calendar.</p>
1172
1173 <p><a id="X87BA46787FF000E8" name="X87BA46787FF000E8"></a></p>
1174
1175 <h5>27.10-1 DaysInYear</h5>
1176
1177 <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>
1178 <p>returns the number of days in the year <var class="Arg">year</var>.</p>
1179
1180 <p><a id="X8791B0B386D59ADB" name="X8791B0B386D59ADB"></a></p>
1181
1182 <h5>27.10-2 DaysInMonth</h5>
1183
1184 <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>
1185 <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>
1186
1187
1188 <div class="example"><pre>
1189 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DaysInYear(1998);</span>
1190 365
1191 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DaysInMonth(3,1998);</span>
1192 31
1193 </pre></div>
1194
1195 <p><a id="X7CED84C07CD5E2CF" name="X7CED84C07CD5E2CF"></a></p>
1196
1197 <h5>27.10-3 DMYDay</h5>
1198
1199 <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>
1200 <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>
1201
1202 <p><a id="X7A79DEE07A41B8EF" name="X7A79DEE07A41B8EF"></a></p>
1203
1204 <h5>27.10-4 DayDMY</h5>
1205
1206 <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>
1207 <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>
1208
1209 <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>
1210
1211 <p><a id="X87D03FC0809DB6EC" name="X87D03FC0809DB6EC"></a></p>
1212
1213 <h5>27.10-5 WeekDay</h5>
1214
1215 <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>
1216 <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>
1217
1218 <p><a id="X7C74C33784CDED6C" name="X7C74C33784CDED6C"></a></p>
1219
1220 <h5>27.10-6 StringDate</h5>
1221
1222 <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>
1223 <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>
1224
1225
1226 <div class="example"><pre>
1227 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DayDMY([1,1,1970]);DayDMY([2,1,1970]);</span>
1228 0
1229 1
1230 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DMYDay(12345);</span>
1231 [ 20, 10, 2003 ]
1232 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">WeekDay([11,3,1998]);</span>
1233 "Wed"
1234 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringDate([11,3,1998]);</span>
1235 "11-Mar-1998"
1236 </pre></div>
1237
1238 <p><a id="X84A6A2637FB35A32" name="X84A6A2637FB35A32"></a></p>
1239
1240 <h5>27.10-7 HMSMSec</h5>
1241
1242 <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>
1243 <p>converts a number <var class="Arg">msec</var> of milliseconds into a list <code class="code">[ hour, min, sec, milli ]</code>.</p>
1244
1245 <p><a id="X879461D77C81100B" name="X879461D77C81100B"></a></p>
1246
1247 <h5>27.10-8 SecHMSM</h5>
1248
1249 <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>
1250 <p>is the reverse of <code class="func">HMSMSec</code> (<a href="chap27.html#X84A6A2637FB35A32"><span class="RefLink">27.10-7</span></a>).</p>
1251
1252 <p><a id="X802469C47F886A59" name="X802469C47F886A59"></a></p>
1253
1254 <h5>27.10-9 StringTime</h5>
1255
1256 <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>
1257 <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>
1258
1259
1260 <div class="example"><pre>
1261 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">HMSMSec(Factorial(10));</span>
1262 [ 1, 0, 28, 800 ]
1263 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SecHMSM([1,10,5,13]);</span>
1264 4205013
1265 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">StringTime([1,10,5,13]);</span>
1266 " 1:10:05.013"
1267 </pre></div>
1268
1269 <p><a id="X870A71D47B0E936E" name="X870A71D47B0E936E"></a></p>
1270
1271 <h5>27.10-10 SecondsDMYhms</h5>
1272
1273 <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>
1274 <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>
1275
1276 <p><a id="X78AF8EA887532B5B" name="X78AF8EA887532B5B"></a></p>
1277
1278 <h5>27.10-11 DMYhmsSeconds</h5>
1279
1280 <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>
1281 <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>
1282
1283
1284 <div class="example"><pre>
1285 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">SecondsDMYhms([ 9, 9, 2001, 1, 46, 40 ]);</span>
1286 1000000000
1287 <span class="GAPprompt">gap&gt;</span> <span class="GAPinput">DMYhmsSeconds(-1000000000);</span>
1288 [ 24, 4, 1938, 22, 13, 20 ]
1289 </pre></div>
1290
1291 <p><a id="X78024C8087F3E07F" name="X78024C8087F3E07F"></a></p>
1292
1293 <h4>27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></h4>
1294
1295 <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>
1296
1297 <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>
1298
1299 <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>
1300
1301 <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>
1302
1303
1304 <div class="chlinkprevnextbot">&nbsp;<a href="chap0.html">[Top of Book]</a>&nbsp; <a href="chap0.html#contents">[Contents]</a>&nbsp; &nbsp;<a href="chap26.html">[Previous Chapter]</a>&nbsp; &nbsp;<a href="chap28.html">[Next Chapter]</a>&nbsp; </div>
1305
1306
1307 <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>
1308
1309 <hr />
1310 <p class="foot">generated by <a href="https://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
1311 </body>
1312 </html>