
| Current Path : /usr/share/gap/doc/ref/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : //usr/share/gap/doc/ref/chap27_mj.html |
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<script type="text/javascript"
src="mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<title>GAP (ref) - Chapter 27: Strings and Characters</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="generator" content="GAPDoc2HTML" />
<link rel="stylesheet" type="text/css" href="manual.css" />
<script src="manual.js" type="text/javascript"></script>
<script type="text/javascript">overwriteStyle();</script>
</head>
<body class="chap27" onload="jscontent()">
<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chap12_mj.html">12</a> <a href="chap13_mj.html">13</a> <a href="chap14_mj.html">14</a> <a href="chap15_mj.html">15</a> <a href="chap16_mj.html">16</a> <a href="chap17_mj.html">17</a> <a href="chap18_mj.html">18</a> <a href="chap19_mj.html">19</a> <a href="chap20_mj.html">20</a> <a href="chap21_mj.html">21</a> <a href="chap22_mj.html">22</a> <a href="chap23_mj.html">23</a> <a href="chap24_mj.html">24</a> <a href="chap25_mj.html">25</a> <a href="chap26_mj.html">26</a> <a href="chap27_mj.html">27</a> <a href="chap28_mj.html">28</a> <a href="chap29_mj.html">29</a> <a href="chap30_mj.html">30</a> <a href="chap31_mj.html">31</a> <a href="chap32_mj.html">32</a> <a href="chap33_mj.html">33</a> <a href="chap34_mj.html">34</a> <a href="chap35_mj.html">35</a> <a href="chap36_mj.html">36</a> <a href="chap37_mj.html">37</a> <a href="chap38_mj.html">38</a> <a href="chap39_mj.html">39</a> <a href="chap40_mj.html">40</a> <a href="chap41_mj.html">41</a> <a href="chap42_mj.html">42</a> <a href="chap43_mj.html">43</a> <a href="chap44_mj.html">44</a> <a href="chap45_mj.html">45</a> <a href="chap46_mj.html">46</a> <a href="chap47_mj.html">47</a> <a href="chap48_mj.html">48</a> <a href="chap49_mj.html">49</a> <a href="chap50_mj.html">50</a> <a href="chap51_mj.html">51</a> <a href="chap52_mj.html">52</a> <a href="chap53_mj.html">53</a> <a href="chap54_mj.html">54</a> <a href="chap55_mj.html">55</a> <a href="chap56_mj.html">56</a> <a href="chap57_mj.html">57</a> <a href="chap58_mj.html">58</a> <a href="chap59_mj.html">59</a> <a href="chap60_mj.html">60</a> <a href="chap61_mj.html">61</a> <a href="chap62_mj.html">62</a> <a href="chap63_mj.html">63</a> <a href="chap64_mj.html">64</a> <a href="chap65_mj.html">65</a> <a href="chap66_mj.html">66</a> <a href="chap67_mj.html">67</a> <a href="chap68_mj.html">68</a> <a href="chap69_mj.html">69</a> <a href="chap70_mj.html">70</a> <a href="chap71_mj.html">71</a> <a href="chap72_mj.html">72</a> <a href="chap73_mj.html">73</a> <a href="chap74_mj.html">74</a> <a href="chap75_mj.html">75</a> <a href="chap76_mj.html">76</a> <a href="chap77_mj.html">77</a> <a href="chap78_mj.html">78</a> <a href="chap79_mj.html">79</a> <a href="chap80_mj.html">80</a> <a href="chap81_mj.html">81</a> <a href="chap82_mj.html">82</a> <a href="chap83_mj.html">83</a> <a href="chap84_mj.html">84</a> <a href="chap85_mj.html">85</a> <a href="chap86_mj.html">86</a> <a href="chap87_mj.html">87</a> <a href="chapBib_mj.html">Bib</a> <a href="chapInd_mj.html">Ind</a> </div>
<div class="chlinkprevnexttop"> <a href="chap0_mj.html">[Top of Book]</a> <a href="chap0_mj.html#contents">[Contents]</a> <a href="chap26_mj.html">[Previous Chapter]</a> <a href="chap28_mj.html">[Next Chapter]</a> </div>
<p id="mathjaxlink" class="pcenter"><a href="chap27.html">[MathJax off]</a></p>
<p><a id="X7D28329B7EDB8F47" name="X7D28329B7EDB8F47"></a></p>
<div class="ChapSects"><a href="chap27_mj.html#X7D28329B7EDB8F47">27 <span class="Heading">Strings and Characters</span></a>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X7A90690B78260194">27.1 <span class="Heading">IsChar and IsString</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X80CFAE128560E064">27.1-1 IsChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X78723B5D795A3B6D">27.1-2 IsString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7B1B45C587A72F96">27.1-3 <span class="Heading">Strings As Lists</span></a>
</span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7EA6CA7486D7E9DD">27.1-4 <span class="Heading">Printing Strings</span></a>
</span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X82E5F5AB818F32DB">27.2 <span class="Heading">Special Characters</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X7E70384E7D0B7083">27.3 <span class="Heading">Triple Quoted Strings</span></a>
</span>
</div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X82AEC07487C45ECD">27.4 <span class="Heading">Internally Represented Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7A17EDF8785C9F58">27.4-1 IsStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7CE2415F7FEC5809">27.4-2 ConvertToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7FFC464683CC8023">27.4-3 CopyToStringRep</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7D944D507CBB24CD">27.4-4 IsEmptyString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X836078DC829A8221">27.4-5 EmptyString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7DA671FC7F490C16">27.4-6 CharsFamily</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X82F980A17FE84AA4">27.5 <span class="Heading">Recognizing Characters</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X78566FD57B95ECBE">27.5-1 IsDigitChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X854114A97BAFEAEA">27.5-2 IsLowerAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87B1A13D81353AD8">27.5-3 IsUpperAlphaChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X84634DF67A431D26">27.5-4 IsAlphaChar</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X8127954B79B8A0DA">27.6 <span class="Heading">Comparisons of Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X79538F138286739A"><code>27.6-1 \=</code></a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8129E3A785F60093"><code>27.6-2 \<</code></a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X7E72717A82A309F5">27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X792FB3A1849FD739">27.7-1 DisplayString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8482132779EA7A23">27.7-2 DEFAULTDISPLAYSTRING</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7803FBCA79DB5529">27.7-3 ViewString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7BBDF9D383595425">27.7-4 DEFAULTVIEWSTRING</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7B3CC87285DEC23D">27.7-5 PrintString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X81FB5BE27903EC32">27.7-6 String</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X86AACCE987F74FA5">27.7-7 StripLineBreakCharacters</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X865FBB7E788017DD">27.7-8 HexStringInt</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7BB1059185AB4F84">27.7-9 StringPP</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X79C8280A853D8FA9">27.7-10 WordAlp</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X798A0F35852ABDAD">27.7-11 LowercaseString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87A2F2557DE7EE08">27.7-12 LowercaseChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7E7E5F5B7FED56A0">27.7-13 UppercaseString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X81E0AEE687200505">27.7-14 UppercaseChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X86E897D486DCFEAB">27.7-15 SplitString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X864F0A9078D4DE0E">27.7-16 ReplacedString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X806379367A53D171">27.7-17 NormalizeWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8685DE9386E57771">27.7-18 NormalizedWhitespace</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X86EBB6EB829723E4">27.7-19 RemoveCharacters</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X84624FEB825EC4B5">27.7-20 JoinStringsWithSeparator</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X79F8FFC5876D854A">27.7-21 Chomp</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X855820848179CC28">27.7-22 StartsWith</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8235AD797868E872">27.7-23 StringFormatted</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7848A9D878FD59BB">27.7-24 NumbersString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X787EAB117816578E">27.7-25 StringNumbers</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X82975B6480932683">27.7-26 StringOfMemoryAmount</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X844BDC8578A3B508">27.8 <span class="Heading">Character Conversion</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X826D95D680F87D23">27.8-1 IntChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87B6C1AF7E4A6639">27.8-2 CharInt</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8159CE81798DDA76">27.8-3 SIntChar</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X78E6611A829DDA3E">27.8-4 CharSInt</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X78D9BD857F890C0A">27.9 <span class="Heading">Operations to Evaluate Strings</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7B6D118184F692A0">27.9-1 Int</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87AD395584294FF2">27.9-2 Rat</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X796D366B7DDEFF67">27.9-3 IntHexString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7C0C29C87CBA97B7">27.9-4 Ordinal</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7DE4CCD285440659">27.9-5 EvalString</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7D4B9D7A7995C55D">27.9-6 CrcString</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X78F20AA1804D524F">27.10 <span class="Heading">Calendar Arithmetic</span></a>
</span>
<div class="ContSSBlock">
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87BA46787FF000E8">27.10-1 DaysInYear</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X8791B0B386D59ADB">27.10-2 DaysInMonth</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7CED84C07CD5E2CF">27.10-3 DMYDay</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7A79DEE07A41B8EF">27.10-4 DayDMY</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X87D03FC0809DB6EC">27.10-5 WeekDay</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X7C74C33784CDED6C">27.10-6 StringDate</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X84A6A2637FB35A32">27.10-7 HMSMSec</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X879461D77C81100B">27.10-8 SecHMSM</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X802469C47F886A59">27.10-9 StringTime</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X870A71D47B0E936E">27.10-10 SecondsDMYhms</a></span>
<span class="ContSS"><br /><span class="nocss"> </span><a href="chap27_mj.html#X78AF8EA887532B5B">27.10-11 DMYhmsSeconds</a></span>
</div></div>
<div class="ContSect"><span class="tocline"><span class="nocss"> </span><a href="chap27_mj.html#X78024C8087F3E07F">27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></a>
</span>
</div>
</div>
<h3>27 <span class="Heading">Strings and Characters</span></h3>
<p><a id="X7A90690B78260194" name="X7A90690B78260194"></a></p>
<h4>27.1 <span class="Heading">IsChar and IsString</span></h4>
<p><a id="X80CFAE128560E064" name="X80CFAE128560E064"></a></p>
<h5>27.1-1 IsChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsChar</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsCharCollection</code>( <var class="Arg">obj</var> )</td><td class="tdright">( category )</td></tr></table></div>
<p>A <em>character</em> is simply an object in <strong class="pkg">GAP</strong> that represents an arbitrary character from the character set of the operating system. Character literals can be entered in <strong class="pkg">GAP</strong> by enclosing the character in <em>singlequotes</em> <code class="code">'</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">x:= 'a'; IsChar( x );</span>
'a'
true
<span class="GAPprompt">gap></span> <span class="GAPinput">'*';</span>
'*'
</pre></div>
<p><a id="X78723B5D795A3B6D" name="X78723B5D795A3B6D"></a></p>
<h5>27.1-2 IsString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( filter )</td></tr></table></div>
<p>A <em>string</em> is a dense list (see <code class="func">IsList</code> (<a href="chap21_mj.html#X7C4CC4EA8299701E"><span class="RefLink">21.1-1</span></a>), <code class="func">IsDenseList</code> (<a href="chap21_mj.html#X870AA9D8798C93DD"><span class="RefLink">21.1-2</span></a>)) of characters (see <code class="func">IsChar</code> (<a href="chap27_mj.html#X80CFAE128560E064"><span class="RefLink">27.1-1</span></a>)); thus strings are always homogeneous (see <code class="func">IsHomogeneousList</code> (<a href="chap21_mj.html#X7C71596C82B6EF35"><span class="RefLink">21.1-3</span></a>)).</p>
<p>A string literal can either be entered as the list of characters or by writing the characters between <em>doublequotes</em> <code class="code">"</code>. <strong class="pkg">GAP</strong> will always output strings in the latter format. However, the input via the double quote syntax enables <strong class="pkg">GAP</strong> to store the string in an efficient compact internal representation. See <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>) below for more details.</p>
<p>Each character, in particular those which cannot be typed directly from the keyboard, can also be typed in three digit octal notation, or two digit hexadecimal notation. And for some special characters (like the newline character) there is a further possibility to type them, see section <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s1 := ['H','e','l','l','o',' ','w','o','r','l','d','.'];</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( s1 );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">s2 := "Hello world.";</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">s1 = s2;</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">s3 := ""; # the empty string</span>
""
<span class="GAPprompt">gap></span> <span class="GAPinput">s3 = [];</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( "123" ); IsString( 123 );</span>
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [ '1', '2', '3' ] );</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [ '1', '2', , '4' ] ); # strings must be dense</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">IsString( [ '1', '2', 3 ] ); # strings must only contain characters</span>
false
</pre></div>
<p><a id="X7B1B45C587A72F96" name="X7B1B45C587A72F96"></a></p>
<h5>27.1-3 <span class="Heading">Strings As Lists</span></h5>
<p>Note that a string is just a special case of a list. So everything that is possible for lists (see <a href="chap21_mj.html#X7B256AE5780F140A"><span class="RefLink">21</span></a>) is also possible for strings. Thus you can access the characters in such a string (see <a href="chap21_mj.html#X7921047F83F5FA28"><span class="RefLink">21.3</span></a>), test for membership (see <a href="chap30_mj.html#X82D39CF980FDBFFA"><span class="RefLink">30.6</span></a>), ask for the length, concatenate strings (see <code class="func">Concatenation</code> (<a href="chap21_mj.html#X840C55A77D1BB2E1"><span class="RefLink">21.20-1</span></a>)), form substrings etc. You can even assign to a mutable string (see <a href="chap21_mj.html#X8611EF768210625B"><span class="RefLink">21.4</span></a>). Of course unless you assign a character in such a way that the list stays dense, the resulting list will no longer be a string.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Length( s2 );</span>
12
<span class="GAPprompt">gap></span> <span class="GAPinput">s2[2];</span>
'e'
<span class="GAPprompt">gap></span> <span class="GAPinput">'a' in s2;</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">s2[2] := 'a';; s2;</span>
"Hallo world."
<span class="GAPprompt">gap></span> <span class="GAPinput">s1{ [1..4] };</span>
"Hell"
<span class="GAPprompt">gap></span> <span class="GAPinput">Concatenation( s1{ [ 1 .. 6 ] }, s1{ [ 1 .. 4 ] } );</span>
"Hello Hell"
</pre></div>
<p><a id="X7EA6CA7486D7E9DD" name="X7EA6CA7486D7E9DD"></a></p>
<h5>27.1-4 <span class="Heading">Printing Strings</span></h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ViewObj</code>( <var class="Arg">str</var> )</td><td class="tdright">( method )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrintObj</code>( <var class="Arg">str</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>If a string is displayed by <code class="func">View</code> (<a href="chap6_mj.html#X851902C583B84CDC"><span class="RefLink">6.3-3</span></a>), for example as result of an evaluation (see <a href="chap6_mj.html#X81667F568237B232"><span class="RefLink">6.1</span></a>), or by <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>), it is displayed with enclosing doublequotes. (But note that there is an ambiguity for the empty string which is also an empty list of arbitrary <strong class="pkg">GAP</strong> objects; it is only printed like a string if it was input as empty string or converted to a string with <code class="func">ConvertToStringRep</code> (<a href="chap27_mj.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>).) The output of <code class="func">PrintObj</code> can be read back into <strong class="pkg">GAP</strong>.</p>
<p>Strings behave differently from other <strong class="pkg">GAP</strong> objects with respect to <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>). These commands <em>interpret</em> a string in the sense that they essentially send the characters of the string directly to the output stream/file. (But depending on the type of the stream and the presence of some special characters used as hints for line breaks there may be sent some additional newline (or backslash and newline) characters.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s4:= "abc\"def\nghi";;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">View( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">ViewObj( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintObj( s4 ); Print( "\n" );</span>
"abc\"def\nghi"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( s4 ); Print( "\n" );</span>
abc"def
ghi
<span class="GAPprompt">gap></span> <span class="GAPinput">s := "German uses strange characters: äöüß\n";</span>
"German uses strange characters: äöüß\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print(s);</span>
German uses strange characters: äöüß
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintObj(s); Print( "\n" );</span>
"German uses strange characters: \303\244\303\266\303\274\303\237\n"
</pre></div>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := "\007";</span>
"\007"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print(s); # rings bell in many terminals</span>
</pre></div>
<p>Note that only those line breaks are printed by <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>) that are contained in the string (<code class="code">\n</code> characters, see <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>), as is shown in the example below.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s1;</span>
"Hello world."
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( s1 );</span>
Hello world.gap> Print( s1, "\n" );
Hello world.
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( s1, "\nnext line\n" );</span>
Hello world.
next line
</pre></div>
<p><a id="X82E5F5AB818F32DB" name="X82E5F5AB818F32DB"></a></p>
<h4>27.2 <span class="Heading">Special Characters</span></h4>
<p>There are a number of <em>special character sequences</em> that can be used between the singlequotes of a character literal or between the doublequotes of a string literal to specify characters. They consist of a backslash <code class="code">\</code> followed by a second character indicating the type of special character sequence, and possibly more characters. The following special character sequences are currently defined. For any other sequence starting with a backslash, the backslash is ignored.</p>
<dl>
<dt><strong class="Mark"><code class="code">\n</code></strong></dt>
<dd><p><em>newline character</em>. This is the character that, at least on UNIX systems, separates lines in a text file. Printing of this character in a string has the effect of moving the cursor down one line and back to the beginning of the line.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\"</code></strong></dt>
<dd><p><em>doublequote character</em>. Inside a string a doublequote must be escaped by the backslash, because it is otherwise interpreted as end of the string.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\'</code></strong></dt>
<dd><p><em>singlequote character</em>. Inside a character a singlequote must escaped by the backslash, because it is otherwise interpreted as end of the character.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\\</code></strong></dt>
<dd><p><em>backslash character</em>. Inside a string a backslash must be escaped by another backslash, because it is otherwise interpreted as first character of an escape sequence.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\b</code></strong></dt>
<dd><p><em>backspace character</em>. Printing this character should have the effect of moving the cursor back one character. Whether it works or not is system dependent and should not be relied upon.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\r</code></strong></dt>
<dd><p><em>carriage return character</em>. Printing this character should have the effect of moving the cursor back to the beginning of the same line. Whether this works or not is again system dependent.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\c</code></strong></dt>
<dd><p><em>flush character</em>. This character is not printed. Its purpose is to flush the output queue. Usually <strong class="pkg">GAP</strong> waits until it sees a <code class="code">newline</code> before it prints a string. If you want to display a string that does not include this character use <code class="code">\c</code>.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\XYZ</code></strong></dt>
<dd><p>with <code class="code">X</code>, <code class="code">Y</code>, <code class="code">Z</code> three octal digits, that is one of <code class="code">"01234567"</code>. This is translated to the character corresponding to the number <code class="code">X * 64 + Y * 8 + Z modulo 256</code>. This can be used to specify and store arbitrary binary data as a string in <strong class="pkg">GAP</strong>.</p>
</dd>
<dt><strong class="Mark">
<code class="code">\0xYZ</code></strong></dt>
<dd><p>with <code class="code">Y</code>, and <code class="code">Z</code> hexadecimal digits, that is one of <code class="code">"0123456789ABCDEFabcdef"</code>, where <code class="code">a</code> to <code class="code">f</code> and <code class="code">A</code> to <code class="code">F</code> are interpreted as the numbers <code class="code">10</code> to <code class="code">15</code>. This is translated to the character corresponding to the number <code class="code">Y*16 + Z</code>.</p>
</dd>
<dt><strong class="Mark">
other</strong></dt>
<dd><p>For any other character the backslash is ignored.</p>
</dd>
</dl>
<p>Again, if the line is displayed as result of an evaluation, those escape sequences are displayed in the same way that they are input.</p>
<p>Only <code class="func">Print</code> (<a href="chap6_mj.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9_mj.html#X86956C577FFEE1F9"><span class="RefLink">9.7-3</span></a>) send the characters directly to the output stream.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">"This is one line.\nThis is another line.\n";</span>
"This is one line.\nThis is another line.\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print( last );</span>
This is one line.
This is another line.
</pre></div>
<p>Note in particular that it is not allowed to enclose a <var class="Arg">newline</var> inside the string. You can use the special character sequence <code class="code">\n</code> to write strings that include <var class="Arg">newline</var> characters. If, however, an input string is too long to fit on a single line it is possible to <em>continue</em> it over several lines. In this case the last character of each input line, except the last line must be a backslash. Both backslash and <var class="Arg">newline</var> are thrown away by <strong class="pkg">GAP</strong> while reading the string. Note that the same continuation mechanism is available for identifiers and integers, see <a href="chap6_mj.html#X866092F281910B74"><span class="RefLink">6.2</span></a>. The rules on escaping are ignored in a triple quoted string, see <a href="chap27_mj.html#X7E70384E7D0B7083"><span class="RefLink">27.3</span></a></p>
<p><a id="X7E70384E7D0B7083" name="X7E70384E7D0B7083"></a></p>
<h4>27.3 <span class="Heading">Triple Quoted Strings</span></h4>
<p>Another method of entering strings in GAP is triple quoted strings. Triple quoted strings ignore the rules on escaping given in <a href="chap27_mj.html#X82E5F5AB818F32DB"><span class="RefLink">27.2</span></a>. Triple quoted strings begin an end with three doublequotes. Inside the triple quotes no escaping is done, and the string continues, including newlines, until three doublequotes are found.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">"""Print("\n")""";</span>
"Print(\"\\n\")"
</pre></div>
<p>Triple quoted strings are represented internally identically to all other strings, they only provide an alternative method of giving strings to GAP. Triple quoted strings still follow GAP's line editing rules (<a href="chap6_mj.html#X866092F281910B74"><span class="RefLink">6.2</span></a>), which state that in normal line editing mode, lines starting <code class="code">gap> </code>, <code class="code">> </code> or <code class="code">brk> </code> will have this beginning part removed.</p>
<p><a id="X82AEC07487C45ECD" name="X82AEC07487C45ECD"></a></p>
<h4>27.4 <span class="Heading">Internally Represented Strings</span></h4>
<p><a id="X7A17EDF8785C9F58" name="X7A17EDF8785C9F58"></a></p>
<h5>27.4-1 IsStringRep</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( representation )</td></tr></table></div>
<p><code class="func">IsStringRep</code> is a special (internal) representation of dense lists of characters. Dense lists of characters can be converted into this representation using <code class="func">ConvertToStringRep</code> (<a href="chap27_mj.html#X7CE2415F7FEC5809"><span class="RefLink">27.4-2</span></a>). Note that calling <code class="func">IsString</code> (<a href="chap27_mj.html#X78723B5D795A3B6D"><span class="RefLink">27.1-2</span></a>) does <em>not</em> change the representation.</p>
<p><a id="X7CE2415F7FEC5809" name="X7CE2415F7FEC5809"></a></p>
<h5>27.4-2 ConvertToStringRep</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ConvertToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>If <var class="Arg">obj</var> is a dense internally represented list of characters then <code class="func">ConvertToStringRep</code> changes the representation to <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). This is useful in particular for converting the empty list <code class="code">[]</code>, which usually is in <code class="code">IsPlistRep</code>, to <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). If <var class="Arg">obj</var> is not a string then <code class="func">ConvertToStringRep</code> signals an error.</p>
<p><a id="X7FFC464683CC8023" name="X7FFC464683CC8023"></a></p>
<h5>27.4-3 CopyToStringRep</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CopyToStringRep</code>( <var class="Arg">obj</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>If <var class="Arg">obj</var> is a dense internally represented list of characters then <code class="func">CopyToStringRep</code> copies <var class="Arg">obj</var> to a new object with representation <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>). If <var class="Arg">obj</var> is not a string then <code class="func">CopyToStringRep</code> signals an error.</p>
<p><a id="X7D944D507CBB24CD" name="X7D944D507CBB24CD"></a></p>
<h5>27.4-4 IsEmptyString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsEmptyString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">IsEmptyString</code> returns <code class="keyw">true</code> if <var class="Arg">str</var> is the empty string in the representation <code class="func">IsStringRep</code> (<a href="chap27_mj.html#X7A17EDF8785C9F58"><span class="RefLink">27.4-1</span></a>), and <code class="keyw">false</code> otherwise. Note that the empty list <code class="code">[]</code> and the empty string <code class="code">""</code> have the same type, the recommended way to distinguish them is via <code class="func">IsEmptyString</code>. For formatted printing, this distinction is sometimes necessary.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:= [];; IsString( l ); IsEmptyString( l ); IsEmpty( l );</span>
true
false
true
<span class="GAPprompt">gap></span> <span class="GAPinput">l; ConvertToStringRep( l ); l;</span>
[ ]
""
<span class="GAPprompt">gap></span> <span class="GAPinput">IsEmptyString( l ); IsEmptyString( "" ); IsEmptyString( "abc" );</span>
true
true
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ll:= [ 'a', 'b' ]; IsStringRep( ll ); ConvertToStringRep( ll );</span>
"ab"
false
<span class="GAPprompt">gap></span> <span class="GAPinput">ll; IsStringRep( ll );</span>
"ab"
true
</pre></div>
<p><a id="X836078DC829A8221" name="X836078DC829A8221"></a></p>
<h5>27.4-5 EmptyString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EmptyString</code>( <var class="Arg">len</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: a string</p>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ShrinkAllocationString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: nothing</p>
<p>The function <code class="func">EmptyString</code> returns an empty string in internal representation which has enough memory allocated for <var class="Arg">len</var> characters. This can be useful for creating and filling a string with a known number of entries.</p>
<p>The function <code class="func">ShrinkAllocationString</code> gives back to <strong class="pkg">GAP</strong>s memory manager the physical memory which is allocated for the string <var class="Arg">str</var> in internal representation but not needed by its current number of characters.</p>
<p>These functions are intended for saving some of <strong class="pkg">GAP</strong>s memory in certain situations, see the explanations and the example for the analogeous functions <code class="func">EmptyPlist</code> (<a href="chap21_mj.html#X78BF67A5802E93AD"><span class="RefLink">21.9-1</span></a>) and <code class="func">ShrinkAllocationPlist</code> (<a href="chap21_mj.html#X78BF67A5802E93AD"><span class="RefLink">21.9-1</span></a>) for plain lists.</p>
<p><a id="X7DA671FC7F490C16" name="X7DA671FC7F490C16"></a></p>
<h5>27.4-6 CharsFamily</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CharsFamily</code></td><td class="tdright">( family )</td></tr></table></div>
<p>Each character lies in the family <code class="func">CharsFamily</code>, each nonempty string lies in the collections family of this family. Note the subtle differences between the empty list <code class="code">[]</code> and the empty string <code class="code">""</code> when both are printed.</p>
<p><a id="X82F980A17FE84AA4" name="X82F980A17FE84AA4"></a></p>
<h4>27.5 <span class="Heading">Recognizing Characters</span></h4>
<p><a id="X78566FD57B95ECBE" name="X78566FD57B95ECBE"></a></p>
<h5>27.5-1 IsDigitChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsDigitChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is a digit, i.e., occurs in the string <code class="code">"0123456789"</code>.</p>
<p><a id="X854114A97BAFEAEA" name="X854114A97BAFEAEA"></a></p>
<h5>27.5-2 IsLowerAlphaChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsLowerAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is a lowercase alphabet letter, i.e., occurs in the string <code class="code">"abcdefghijklmnopqrstuvwxyz"</code>.</p>
<p><a id="X87B1A13D81353AD8" name="X87B1A13D81353AD8"></a></p>
<h5>27.5-3 IsUpperAlphaChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsUpperAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is an uppercase alphabet letter, i.e., occurs in the string <code class="code">"ABCDEFGHIJKLMNOPQRSTUVWXYZ"</code>.</p>
<p><a id="X84634DF67A431D26" name="X84634DF67A431D26"></a></p>
<h5>27.5-4 IsAlphaChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IsAlphaChar</code>( <var class="Arg">c</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>checks whether the character <var class="Arg">c</var> is either a lowercase or an uppercase alphabet letter.</p>
<p><a id="X8127954B79B8A0DA" name="X8127954B79B8A0DA"></a></p>
<h4>27.6 <span class="Heading">Comparisons of Strings</span></h4>
<p><a id="X79538F138286739A" name="X79538F138286739A"></a></p>
<h5><code>27.6-1 \=</code></h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \=</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>The equality operator <code class="code">=</code> returns <code class="keyw">true</code> if the two strings <var class="Arg">string1</var> and <var class="Arg">string2</var> are equal and <code class="keyw">false</code> otherwise. The inequality operator <code class="code"><></code> returns <code class="keyw">true</code> if the two strings <var class="Arg">string1</var> and <var class="Arg">string2</var> are not equal and <code class="keyw">false</code> otherwise.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world.\n" = "Hello world.\n";</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello World.\n" = "Hello world.\n"; # comparison is case sensitive</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world." = "Hello world.\n"; # first string has no <newline></span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">"Goodbye world.\n" = "Hello world.\n";</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput">[ 'a', 'b' ] = "ab";</span>
true
</pre></div>
<p><a id="X8129E3A785F60093" name="X8129E3A785F60093"></a></p>
<h5><code>27.6-2 \<</code></h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ \<</code>( <var class="Arg">string1</var>, <var class="Arg">string2</var> )</td><td class="tdright">( method )</td></tr></table></div>
<p>The ordering of strings is lexicographically according to the order implied by the underlying, system dependent, character set.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world.\n" < "Hello world.\n"; # the strings are equal</span>
false
<span class="GAPprompt">gap></span> <span class="GAPinput"># in ASCII capitals range before small letters:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello World." < "Hello world.";</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput">"Hello world." < "Hello world.\n"; # prefixes are always smaller</span>
true
<span class="GAPprompt">gap></span> <span class="GAPinput"># G comes before H, in ASCII at least:</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">"Goodbye world.\n" < "Hello world.\n";</span>
true
</pre></div>
<p>Strings can be compared via <code class="code"><</code> with certain <strong class="pkg">GAP</strong> objects that are not strings, see <a href="chap4_mj.html#X7A274A1F8553B7E6"><span class="RefLink">4.12</span></a> for the details.</p>
<p><a id="X7E72717A82A309F5" name="X7E72717A82A309F5"></a></p>
<h4>27.7 <span class="Heading">Operations to Produce or Manipulate Strings</span></h4>
<p>For the possibility to print <strong class="pkg">GAP</strong> objects to strings, see <a href="chap10_mj.html#X8028E1D87CE2F059"><span class="RefLink">10.7</span></a>.</p>
<p><a id="X792FB3A1849FD739" name="X792FB3A1849FD739"></a></p>
<h5>27.7-1 DisplayString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DisplayString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p>Returns a string which could be used to display the object <var class="Arg">obj</var> in a nice, formatted way which is easy to read (but might be difficult for machines to understand). The actual format used for this depends on the type of <var class="Arg">obj</var>. Each method should include a newline character as last character. Note that no method for <code class="func">DisplayString</code> may delegate to any of the operations <code class="func">Display</code> (<a href="chap6_mj.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) or <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to avoid circular delegations.</p>
<p><a id="X8482132779EA7A23" name="X8482132779EA7A23"></a></p>
<h5>27.7-2 DEFAULTDISPLAYSTRING</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DEFAULTDISPLAYSTRING</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This is the default value for <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>).</p>
<p><a id="X7803FBCA79DB5529" name="X7803FBCA79DB5529"></a></p>
<h5>27.7-3 ViewString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ViewString</code>( <var class="Arg">obj</var> )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">ViewString</code> returns a string which would be displayed by <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) for an object. Note that no method for <code class="func">ViewString</code> may delegate to any of the operations <code class="func">Display</code> (<a href="chap6_mj.html#X83A5C59278E13248"><span class="RefLink">6.3-6</span></a>), <code class="func">ViewObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>), <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>) or <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to avoid circular delegations.</p>
<p><a id="X7BBDF9D383595425" name="X7BBDF9D383595425"></a></p>
<h5>27.7-4 DEFAULTVIEWSTRING</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DEFAULTVIEWSTRING</code></td><td class="tdright">( global variable )</td></tr></table></div>
<p>This is the default value for <code class="func">ViewString</code> (<a href="chap27_mj.html#X7803FBCA79DB5529"><span class="RefLink">27.7-3</span></a>).</p>
<p><a id="X7B3CC87285DEC23D" name="X7B3CC87285DEC23D"></a></p>
<h5>27.7-5 PrintString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrintString</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p><code class="func">PrintString</code> returns a representation of <var class="Arg">obj</var>, which may be an object of arbitrary type, as a string. This string should approximate as closely as possible the character sequence you see if you print <var class="Arg">obj</var> using <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>).</p>
<p>If <var class="Arg">length</var> is given it must be an integer. The absolute value gives the minimal length of the result. If the string representation of <var class="Arg">obj</var> takes less than that many characters it is filled with blanks. If <var class="Arg">length</var> is positive it is filled on the left, if <var class="Arg">length</var> is negative it is filled on the right.</p>
<p>In the two argument case, the string returned is a new mutable string (in particular not a part of any other object); it can be modified safely, and <code class="func">MakeImmutable</code> (<a href="chap12_mj.html#X80CE136D804097C7"><span class="RefLink">12.6-4</span></a>) may be safely applied to it.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">PrintString(123);PrintString([1,2,3]);</span>
"123"
"[ 1, 2, 3 ]"
</pre></div>
<p><code class="func">PrintString</code> is entitled to put in additional control characters <code class="code">\<</code> (ASCII 1) and <code class="code">\></code> (ASCII 2) that allow proper line breaks. See <code class="func">StripLineBreakCharacters</code> (<a href="chap27_mj.html#X86AACCE987F74FA5"><span class="RefLink">27.7-7</span></a>) for a function to get rid of these control characters.</p>
<p><a id="X81FB5BE27903EC32" name="X81FB5BE27903EC32"></a></p>
<h5>27.7-6 String</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ String</code>( <var class="Arg">obj</var>[, <var class="Arg">length</var>] )</td><td class="tdright">( attribute )</td></tr></table></div>
<p><code class="func">String</code> returns a representation of <var class="Arg">obj</var>, which may be an object of arbitrary type, as a string. This string should approximate as closely as possible the character sequence you see if you print <var class="Arg">obj</var>.</p>
<p>If <var class="Arg">length</var> is given it must be an integer. The absolute value gives the minimal length of the result. If the string representation of <var class="Arg">obj</var> takes less than that many characters it is filled with blanks. If <var class="Arg">length</var> is positive it is filled on the left, if <var class="Arg">length</var> is negative it is filled on the right.</p>
<p>In the two argument case, the string returned is a new mutable string (in particular not a part of any other object); it can be modified safely, and <code class="func">MakeImmutable</code> (<a href="chap12_mj.html#X80CE136D804097C7"><span class="RefLink">12.6-4</span></a>) may be safely applied to it.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">String(123);String([1,2,3]);</span>
"123"
"[ 1, 2, 3 ]"
</pre></div>
<p><code class="func">String</code> must not put in additional control characters <code class="code">\<</code> (ASCII 1) and <code class="code">\></code> (ASCII 2) that allow proper line breaks.</p>
<p><a id="X86AACCE987F74FA5" name="X86AACCE987F74FA5"></a></p>
<h5>27.7-7 StripLineBreakCharacters</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StripLineBreakCharacters</code>( <var class="Arg">st</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function takes a string <var class="Arg">st</var> as an argument and removes all control characters <code class="code">\<</code> (ASCII 1) and <code class="code">\></code> (ASCII 2) which are used by <code class="func">PrintString</code> (<a href="chap27_mj.html#X7B3CC87285DEC23D"><span class="RefLink">27.7-5</span></a>) and <code class="func">PrintObj</code> (<a href="chap6_mj.html#X815BF22186FD43C9"><span class="RefLink">6.3-5</span></a>) to ensure proper line breaking. A new string with these characters removed is returned.</p>
<p><a id="X865FBB7E788017DD" name="X865FBB7E788017DD"></a></p>
<h5>27.7-8 HexStringInt</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ HexStringInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string which represents the integer <var class="Arg">int</var> with hexadecimal digits (using <code class="code">A</code> to <code class="code">F</code> as digits <code class="code">10</code> to <code class="code">15</code>). The inverse translation can be achieved with <code class="func">IntHexString</code> (<a href="chap27_mj.html#X796D366B7DDEFF67"><span class="RefLink">27.9-3</span></a>).</p>
<p><a id="X7BB1059185AB4F84" name="X7BB1059185AB4F84"></a></p>
<h5>27.7-9 StringPP</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringPP</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string representing the prime factor decomposition of the integer <var class="Arg">int</var>. See also <code class="func">PrintFactorsInt</code> (<a href="chap14_mj.html#X803D431087B6FF28"><span class="RefLink">14.4-10</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">StringPP(40320);</span>
"2^7*3^2*5*7"
</pre></div>
<p><a id="X79C8280A853D8FA9" name="X79C8280A853D8FA9"></a></p>
<h5>27.7-10 WordAlp</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WordAlp</code>( <var class="Arg">alpha</var>, <var class="Arg">nr</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a string that is the <var class="Arg">nr</var>-th word over the alphabet list <var class="Arg">alpha</var>, w.r.t. word length and lexicographical order. The empty word is <code class="code">WordAlp( <var class="Arg">alpha</var>, 0 )</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">List([0..5],i->WordAlp("abc",i));</span>
[ "", "a", "b", "c", "aa", "ab" ]
</pre></div>
<p><a id="X798A0F35852ABDAD" name="X798A0F35852ABDAD"></a></p>
<h5>27.7-11 LowercaseString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ LowercaseString</code>( <var class="Arg">string</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns a lowercase version of the string <var class="Arg">string</var>, that is, a string in which each uppercase alphabet character is replaced by the corresponding lowercase character.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">LowercaseString("This Is UpperCase");</span>
"this is uppercase"
</pre></div>
<p><a id="X87A2F2557DE7EE08" name="X87A2F2557DE7EE08"></a></p>
<h5>27.7-12 LowercaseChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ LowercaseChar</code>( <var class="Arg">character</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns the lowercase version of the character <var class="Arg">character</var>.</p>
<p><a id="X7E7E5F5B7FED56A0" name="X7E7E5F5B7FED56A0"></a></p>
<h5>27.7-13 UppercaseString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ UppercaseString</code>( <var class="Arg">string</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns a uppercase version of the string <var class="Arg">string</var>, that is, a string in which each lowercase alphabet character is replaced by the corresponding uppercase character.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">UppercaseString("This Is UpperCase");</span>
"THIS IS UPPERCASE"
</pre></div>
<p><a id="X81E0AEE687200505" name="X81E0AEE687200505"></a></p>
<h5>27.7-14 UppercaseChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ UppercaseChar</code>( <var class="Arg">character</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns the uppercase version of the character <var class="Arg">character</var>.</p>
<p><a id="X86E897D486DCFEAB" name="X86E897D486DCFEAB"></a></p>
<h5>27.7-15 SplitString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SplitString</code>( <var class="Arg">string</var>, <var class="Arg">seps</var>[, <var class="Arg">wspace</var>] )</td><td class="tdright">( operation )</td></tr></table></div>
<p>This function accepts a string <var class="Arg">string</var> and lists <var class="Arg">seps</var> and, optionally, <var class="Arg">wspace</var> of characters. Now <var class="Arg">string</var> is split into substrings at each occurrence of a character in <var class="Arg">seps</var> or <var class="Arg">wspace</var>. The characters in <var class="Arg">wspace</var> are interpreted as white space characters. Substrings of characters in <var class="Arg">wspace</var> are treated as one white space character and they are ignored at the beginning and end of a string.</p>
<p>Both arguments <var class="Arg">seps</var> and <var class="Arg">wspace</var> can be single characters.</p>
<p>Each string in the resulting list of substring does not contain any characters in <var class="Arg">seps</var> or <var class="Arg">wspace</var>.</p>
<p>A character that occurs both in <var class="Arg">seps</var> and <var class="Arg">wspace</var> is treated as a white space character.</p>
<p>A separator at the end of a string is interpreted as a terminator; in this case, the separator does not produce a trailing empty string. Also see <code class="func">Chomp</code> (<a href="chap27_mj.html#X79F8FFC5876D854A"><span class="RefLink">27.7-21</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString( "substr1:substr2::substr4", ":" );</span>
[ "substr1", "substr2", "", "substr4" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString( "a;b;c;d;", ";" );</span>
[ "a", "b", "c", "d" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString( "/home//user//dir/", "", "/" );</span>
[ "home", "user", "dir" ]
</pre></div>
<p><a id="X864F0A9078D4DE0E" name="X864F0A9078D4DE0E"></a></p>
<h5>27.7-16 ReplacedString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ ReplacedString</code>( <var class="Arg">string</var>, <var class="Arg">old</var>, <var class="Arg">new</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>replaces occurrences of the string <var class="Arg">old</var> in <var class="Arg">string</var> by <var class="Arg">new</var>, starting from the left and always replacing the first occurrence. To avoid infinite recursion, characters which have been replaced already, are not subject to renewed replacement.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">ReplacedString("abacab","a","zl");</span>
"zlbzlczlb"
<span class="GAPprompt">gap></span> <span class="GAPinput">ReplacedString("ababa", "aba","c");</span>
"cba"
<span class="GAPprompt">gap></span> <span class="GAPinput">ReplacedString("abacab","a","ba");</span>
"babbacbab"
</pre></div>
<p><a id="X806379367A53D171" name="X806379367A53D171"></a></p>
<h5>27.7-17 NormalizeWhitespace</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NormalizeWhitespace</code>( <var class="Arg">string</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function changes the string <var class="Arg">string</var> in place. The characters <code class="code"> </code> (space), <code class="code">\n</code>, <code class="code">\r</code> and <code class="code">\t</code> are considered as <em>white space</em>. Leading and trailing white space characters in <var class="Arg">string</var> are removed. Sequences of white space characters between other characters are replaced by a single space character.</p>
<p>See <code class="func">NormalizedWhitespace</code> (<a href="chap27_mj.html#X8685DE9386E57771"><span class="RefLink">27.7-18</span></a>) for a non-destructive version.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := " x y \n\n\t\r z\n \n";</span>
" x y \n\n\t\r z\n \n"
<span class="GAPprompt">gap></span> <span class="GAPinput">NormalizeWhitespace(s);</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span>
"x y z"
</pre></div>
<p><a id="X8685DE9386E57771" name="X8685DE9386E57771"></a></p>
<h5>27.7-18 NormalizedWhitespace</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NormalizedWhitespace</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns a copy of string <var class="Arg">str</var> to which <code class="func">NormalizeWhitespace</code> (<a href="chap27_mj.html#X806379367A53D171"><span class="RefLink">27.7-17</span></a>) was applied.</p>
<p><a id="X86EBB6EB829723E4" name="X86EBB6EB829723E4"></a></p>
<h5>27.7-19 RemoveCharacters</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ RemoveCharacters</code>( <var class="Arg">string</var>, <var class="Arg">chars</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Both arguments must be strings. This function efficiently removes all characters given in <var class="Arg">chars</var> from <var class="Arg">string</var>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s := "ab c\ndef\n\ng h i .\n";</span>
"ab c\ndef\n\ng h i .\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">RemoveCharacters(s, " \n\t\r"); # remove all whitespace characters</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">s;</span>
"abcdefghi."
</pre></div>
<p><a id="X84624FEB825EC4B5" name="X84624FEB825EC4B5"></a></p>
<h5>27.7-20 JoinStringsWithSeparator</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ JoinStringsWithSeparator</code>( <var class="Arg">list</var>[, <var class="Arg">sep</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p>joins <var class="Arg">list</var> (a list of strings) after interpolating <var class="Arg">sep</var> (or <code class="code">","</code> if the second argument is omitted) between each adjacent pair of strings; <var class="Arg">sep</var> should be a string.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">list := List([1..10], String);</span>
[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]
<span class="GAPprompt">gap></span> <span class="GAPinput">JoinStringsWithSeparator(list);</span>
"1,2,3,4,5,6,7,8,9,10"
<span class="GAPprompt">gap></span> <span class="GAPinput">JoinStringsWithSeparator(["The", "quick", "brown", "fox"], " ");</span>
"The quick brown fox"
<span class="GAPprompt">gap></span> <span class="GAPinput">new:= JoinStringsWithSeparator(["a", "b", "c", "d"], ",\n ");</span>
"a,\n b,\n c,\n d"
<span class="GAPprompt">gap></span> <span class="GAPinput">Print(" ", new, "\n");</span>
a,
b,
c,
d
</pre></div>
<p><a id="X79F8FFC5876D854A" name="X79F8FFC5876D854A"></a></p>
<h5>27.7-21 Chomp</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Chomp</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Like the similarly named Perl function, <code class="func">Chomp</code> removes a trailing newline character (or carriage-return line-feed couplet) from a string argument <var class="Arg">str</var> if present and returns the result. If <var class="Arg">str</var> is not a string or does not have such trailing character(s) it is returned unchanged. This latter property means that <code class="func">Chomp</code> is safe to use in cases where one is manipulating the result of another function which might sometimes return <code class="keyw">fail</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\n");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.\r\n");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp("The quick brown fox jumps over the lazy dog.");</span>
"The quick brown fox jumps over the lazy dog."
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp(fail);</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp(32);</span>
32
</pre></div>
<p><em>Note:</em> <code class="func">Chomp</code> only removes a trailing newline character from <var class="Arg">str</var>. If your string contains several newline characters and you really want to split <var class="Arg">str</var> into lines at the newline characters (and remove those newline characters) then you should use <code class="func">SplitString</code> (<a href="chap27_mj.html#X86E897D486DCFEAB"><span class="RefLink">27.7-15</span></a>), e.g.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">str := "The quick brown fox\njumps over the lazy dog.\n";</span>
"The quick brown fox\njumps over the lazy dog.\n"
<span class="GAPprompt">gap></span> <span class="GAPinput">SplitString(str, "", "\n");</span>
[ "The quick brown fox", "jumps over the lazy dog." ]
<span class="GAPprompt">gap></span> <span class="GAPinput">Chomp(str);</span>
"The quick brown fox\njumps over the lazy dog."
</pre></div>
<p><a id="X855820848179CC28" name="X855820848179CC28"></a></p>
<h5>27.7-22 StartsWith</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StartsWith</code>( <var class="Arg">string</var>, <var class="Arg">prefix</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EndsWith</code>( <var class="Arg">string</var>, <var class="Arg">suffix</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Determines whether a string starts or ends with another string.</p>
<p><a id="X8235AD797868E872" name="X8235AD797868E872"></a></p>
<h5>27.7-23 StringFormatted</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringFormatted</code>( <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrintFormatted</code>( <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ PrintToFormatted</code>( <var class="Arg">stream</var>, <var class="Arg">string</var>, <var class="Arg">data...</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>These functions perform a string formatting operation. They accept a format string, which can contain replacement fields which are delimited by braces {}. Each replacement field contains a numeric or positional argument, describing the element of <var class="Arg">data</var> to replace the braces with.</p>
<p>There are three formatting functions, which differ only in how they output the formatted string. <code class="func">StringFormatted</code> returns the formatted string, <code class="func">PrintFormatted</code> prints the formatted string and <code class="func">PrintToFormatted</code> appends the formatted string to <var class="Arg">stream</var>, which can be either an output stream or a filename.</p>
<p>The arguments after <var class="Arg">string</var> form a list <var class="Arg">data</var> of values used to substitute the replacement fields in <var class="Arg">string</var>, using the following formatting rules:</p>
<p><var class="Arg">string</var> is treated as a normal string, except for occurrences of <code class="code">{</code> and <code class="code">}</code>, which follow special rules, as follows:</p>
<p>The contents of <code class="code">{ }</code> is split by a <code class="code">!</code> into <code class="code">{id!format}</code>, where both <code class="code">id</code> and <code class="code">format</code> are optional. If the <code class="code">!</code> is ommitted, the bracket is treated as <code class="code">{id}</code> with no <code class="code">format</code>.</p>
<p><code class="code">id</code> is interpreted as follows:</p>
<dl>
<dt><strong class="Mark">An integer <code class="code">i</code></strong></dt>
<dd><p>Take the <code class="code">i</code>th element of <var class="Arg">data</var>.</p>
</dd>
<dt><strong class="Mark">A string <code class="code">str</code></strong></dt>
<dd><p>If this is used, the first element of <var class="Arg">data</var> must be a record <code class="code">r</code>. In this case, the value <code class="code">r.(str)</code> is taken.</p>
</dd>
<dt><strong class="Mark">No id given</strong></dt>
<dd><p>Take the <code class="code">j</code>th element of <var class="Arg">data</var>, where <code class="code">j</code> is the number of replacement fields with no id in the format string so far. If any replacement field has no id, then all replacement fields must have no id.</p>
</dd>
</dl>
<p>A single brace can be outputted by doubling, so <code class="code">{{</code> in the format string produces <code class="code">{</code> and <code class="code">}}</code> produces <code class="code">}</code>.</p>
<p>The <code class="code">format</code> decides how the variable is printed. <code class="code">format</code> must be one of <code class="code">s</code> (which uses <code class="func">String</code> (<a href="chap27_mj.html#X81FB5BE27903EC32"><span class="RefLink">27.7-6</span></a>)), <code class="code">v</code> (which uses <code class="func">ViewString</code> (<a href="chap27_mj.html#X7803FBCA79DB5529"><span class="RefLink">27.7-3</span></a>)) or <code class="code">d</code> (which calls <code class="func">DisplayString</code> (<a href="chap27_mj.html#X792FB3A1849FD739"><span class="RefLink">27.7-1</span></a>)). The default value for <code class="code">format</code> is <code class="code">s</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">StringFormatted("I have {} cats and {} dogs", 4, 5);</span>
"I have 4 cats and 5 dogs"
<span class="GAPprompt">gap></span> <span class="GAPinput">StringFormatted("I have {2} cats and {1} dogs", 4, 5);</span>
"I have 5 cats and 4 dogs"
<span class="GAPprompt">gap></span> <span class="GAPinput">StringFormatted("I have {cats} cats and {dogs} dogs", rec(cats:=3, dogs:=2));</span>
"I have 3 cats and 2 dogs"
<span class="GAPprompt">gap></span> <span class="GAPinput">StringFormatted("We use {{ and }} to mark {dogs} dogs", rec(cats:=3, dogs:=2));</span>
"We use { and } to mark 2 dogs"
<span class="GAPprompt">gap></span> <span class="GAPinput">sym3 := SymmetricGroup(3);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">StringFormatted("String: {1!s}, ViewString: {1!v}", sym3);</span>
"String: SymmetricGroup( [ 1 .. 3 ] ), ViewString: Sym( [ 1 .. 3 ] )"
</pre></div>
<p>The following two functions convert basic strings to lists of numbers and vice versa. They are useful for examples of text encryption.</p>
<p><a id="X7848A9D878FD59BB" name="X7848A9D878FD59BB"></a></p>
<h5>27.7-24 NumbersString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ NumbersString</code>( <var class="Arg">s</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">NumbersString</code> takes a string message <var class="Arg">s</var> and returns a list of integers, each not exceeding the integer <var class="Arg">m</var> that encode the message using the scheme <span class="SimpleMath">\(A=11\)</span>, <span class="SimpleMath">\(B=12\)</span> and so on (and converting lower case to upper case). If a list of characters is given in <var class="Arg">table</var>, it is used instead for encoding).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">l:=NumbersString("Twas brillig and the slithy toves",1000000);</span>
[ 303311, 291012, 281922, 221917, 101124, 141030, 181510, 292219,
301835, 103025, 321529 ]
</pre></div>
<p><a id="X787EAB117816578E" name="X787EAB117816578E"></a></p>
<h5>27.7-25 StringNumbers</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringNumbers</code>( <var class="Arg">l</var>, <var class="Arg">m</var>[, <var class="Arg">table</var>] )</td><td class="tdright">( function )</td></tr></table></div>
<p><code class="func">StringNumbers</code> takes a list <var class="Arg">l</var> of integers that was encoded using <code class="func">NumbersString</code> (<a href="chap27_mj.html#X7848A9D878FD59BB"><span class="RefLink">27.7-24</span></a>) and the size integer <var class="Arg">m</var>, and returns a message string, using the scheme <span class="SimpleMath">\(A=11\)</span>, <span class="SimpleMath">\(B=12\)</span> and so on. If a list of characters is given in <var class="Arg">table</var>, it is used instead for decoding).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">StringNumbers(l,1000000);</span>
"TWAS BRILLIG AND THE SLITHY TOVES"
</pre></div>
<p><a id="X82975B6480932683" name="X82975B6480932683"></a></p>
<h5>27.7-26 StringOfMemoryAmount</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringOfMemoryAmount</code>( <var class="Arg">numbytes</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This function returns a human-readable string representing <var class="Arg">numbytes</var> of memory. It is used in printing amounts of memory allocated by tests and benchmarks. Binary prefixes (representing powers of 1024) are used.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">StringOfMemoryAmount(123456789);</span>
"117MB"
</pre></div>
<p><a id="X844BDC8578A3B508" name="X844BDC8578A3B508"></a></p>
<h4>27.8 <span class="Heading">Character Conversion</span></h4>
<p>The following functions convert characters in their internal integer values and vice versa. Note that the number corresponding to a particular character might depend on the system used. While most systems use an extension of ASCII, in particular character values outside the range <code class="code">[ 32 .. 126 ]</code> might differ between architectures.</p>
<p><a id="X826D95D680F87D23" name="X826D95D680F87D23"></a></p>
<h5>27.8-1 IntChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns an integer value in the range <code class="code">[ 0 .. 255 ]</code> that corresponds to <var class="Arg">char</var>.</p>
<p><a id="X87B6C1AF7E4A6639" name="X87B6C1AF7E4A6639"></a></p>
<h5>27.8-2 CharInt</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CharInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a character that corresponds to the integer value <var class="Arg">int</var>, which must be in the range <code class="code">[ 0 .. 255 ]</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">c:=CharInt(65);</span>
'A'
<span class="GAPprompt">gap></span> <span class="GAPinput">IntChar(c);</span>
65
</pre></div>
<p><a id="X8159CE81798DDA76" name="X8159CE81798DDA76"></a></p>
<h5>27.8-3 SIntChar</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SIntChar</code>( <var class="Arg">char</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a signed integer value in the range <code class="code">[ -128 .. 127 ]</code> that corresponds to <var class="Arg">char</var>.</p>
<p><a id="X78E6611A829DDA3E" name="X78E6611A829DDA3E"></a></p>
<h5>27.8-4 CharSInt</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CharSInt</code>( <var class="Arg">int</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns a character which corresponds to the signed integer value <var class="Arg">int</var>, which must be in the range <code class="code">[ -128 .. 127 ]</code>.</p>
<p>The signed and unsigned integer functions behave the same for values in the range <code class="code">[ 0 .. 127 ]</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SIntChar(c);</span>
65
<span class="GAPprompt">gap></span> <span class="GAPinput">c:=CharSInt(-20);;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">SIntChar(c);</span>
-20
<span class="GAPprompt">gap></span> <span class="GAPinput">IntChar(c);</span>
236
<span class="GAPprompt">gap></span> <span class="GAPinput">SIntChar(CharInt(255));</span>
-1
</pre></div>
<p><a id="X78D9BD857F890C0A" name="X78D9BD857F890C0A"></a></p>
<h4>27.9 <span class="Heading">Operations to Evaluate Strings</span></h4>
<p><a id="X7B6D118184F692A0" name="X7B6D118184F692A0"></a></p>
<h5>27.9-1 Int</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Int</code>( <var class="Arg">str</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>returns an integer as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by a sequence of decimal digits. For any other input <code class="keyw">fail</code> is returned.</p>
<p>For backwards compatibility, the empty string is accepted, in which case <span class="SimpleMath">\(0\)</span> is returned as result.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("12345");</span>
12345
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("123/45");</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("1+2");</span>
fail
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("-12");</span>
-12
<span class="GAPprompt">gap></span> <span class="GAPinput">Int("");</span>
0
</pre></div>
<p><a id="X87AD395584294FF2" name="X87AD395584294FF2"></a></p>
<h5>27.9-2 Rat</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Rat</code>( <var class="Arg">str</var> )</td><td class="tdright">( attribute )</td></tr></table></div>
<p>returns a rational as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by either a sequence of decimal digits or by two sequences of decimal digits that are separated by one of the characters <code class="code">/</code> or <code class="code">.</code>, where the latter stands for a decimal dot. For any other input <code class="keyw">fail</code> is returned.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat("123/45");</span>
41/15
<span class="GAPprompt">gap></span> <span class="GAPinput">Rat("-123.45");</span>
-2469/20
</pre></div>
<p><a id="X796D366B7DDEFF67" name="X796D366B7DDEFF67"></a></p>
<h5>27.9-3 IntHexString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ IntHexString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns an integer as represented by the string <var class="Arg">str</var>. The argument string may optionally start with the sign character <code class="code">-</code>, followed by a sequence of hexadecimal digits. Here the letters <code class="code">a</code>-<code class="code">f</code> or <code class="code">A</code>-<code class="code">F</code> are used as <em>digits</em> <span class="SimpleMath">\(10\)</span> to <span class="SimpleMath">\(15\)</span>. Any other input results in an error.</p>
<p>This function can be used (together with <code class="func">HexStringInt</code> (<a href="chap27_mj.html#X865FBB7E788017DD"><span class="RefLink">27.7-8</span></a>)) for efficiently storing and reading large integers from respectively into <strong class="pkg">GAP</strong>. Note that the translation between integers and their hexadecimal representation costs linear computation time in terms of the number of digits, while translation from and into decimal representation needs substantial computations.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">IntHexString("-abcdef0123456789");</span>
-12379813738877118345
<span class="GAPprompt">gap></span> <span class="GAPinput">HexStringInt(last);</span>
"-ABCDEF0123456789"
</pre></div>
<p><a id="X7C0C29C87CBA97B7" name="X7C0C29C87CBA97B7"></a></p>
<h5>27.9-4 Ordinal</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ Ordinal</code>( <var class="Arg">n</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the ordinal of the integer <var class="Arg">n</var> as a string.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">Ordinal(2); Ordinal(21); Ordinal(33); Ordinal(-33);</span>
"2nd"
"21st"
"33rd"
"-33rd"
</pre></div>
<p><a id="X7DE4CCD285440659" name="X7DE4CCD285440659"></a></p>
<h5>27.9-5 EvalString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ EvalString</code>( <var class="Arg">expr</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>passes the string <var class="Arg">expr</var> through an input text stream so that <strong class="pkg">GAP</strong> interprets it, and returns the result.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">a:=10;</span>
10
<span class="GAPprompt">gap></span> <span class="GAPinput">EvalString("a^2");</span>
100
</pre></div>
<p><code class="func">EvalString</code> is intended for <em>single</em> expressions. A sequence of commands may be interpreted by using the functions <code class="func">InputTextString</code> (<a href="chap10_mj.html#X7ABABCDF7ED81F7F"><span class="RefLink">10.7-1</span></a>) and <code class="func">ReadAsFunction</code> (<a href="chap10_mj.html#X7D62F2877F0E45A7"><span class="RefLink">10.3-2</span></a>) together; see <a href="chap10_mj.html#X7D1D33A587BFD93D"><span class="RefLink">10.3</span></a> for an example.</p>
<p>If <code class="func">EvalString</code> is used inside a function, then it doesn't know about the local variables and the arguments of the function. A possible workaround is to define global variables in advance, and then to assign the values of the local variables to the global ones, like in the example below.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">global_a := 0;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">global_b := 0;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">example := function ( local_a )</span>
<span class="GAPprompt">></span> <span class="GAPinput"> local local_b;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> local_b := 5;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> global_a := local_a;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> global_b := local_b;</span>
<span class="GAPprompt">></span> <span class="GAPinput"> return EvalString( "global_a * global_b" );</span>
<span class="GAPprompt">></span> <span class="GAPinput">end;;</span>
<span class="GAPprompt">gap></span> <span class="GAPinput">example( 2 );</span>
10
</pre></div>
<p><a id="X7D4B9D7A7995C55D" name="X7D4B9D7A7995C55D"></a></p>
<h5>27.9-6 CrcString</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ CrcString</code>( <var class="Arg">str</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>Returns: an integer</p>
<p>This function computes a cyclic redundancy check number from a string <var class="Arg">str</var>. See also <code class="func">CrcFile</code> (<a href="chap9_mj.html#X8241CEAD80415BB9"><span class="RefLink">9.7-7</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">CrcString("GAP example string");</span>
-50451670
</pre></div>
<p><a id="X78F20AA1804D524F" name="X78F20AA1804D524F"></a></p>
<h4>27.10 <span class="Heading">Calendar Arithmetic</span></h4>
<p>All calendar functions use the Gregorian calendar.</p>
<p><a id="X87BA46787FF000E8" name="X87BA46787FF000E8"></a></p>
<h5>27.10-1 DaysInYear</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DaysInYear</code>( <var class="Arg">year</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the number of days in the year <var class="Arg">year</var>.</p>
<p><a id="X8791B0B386D59ADB" name="X8791B0B386D59ADB"></a></p>
<h5>27.10-2 DaysInMonth</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DaysInMonth</code>( <var class="Arg">month</var>, <var class="Arg">year</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the number of days in month number <var class="Arg">month</var> of <var class="Arg">year</var>, and <code class="keyw">fail</code> if <code class="code">month</code> is not in the valid range.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">DaysInYear(1998);</span>
365
<span class="GAPprompt">gap></span> <span class="GAPinput">DaysInMonth(3,1998);</span>
31
</pre></div>
<p><a id="X7CED84C07CD5E2CF" name="X7CED84C07CD5E2CF"></a></p>
<h5>27.10-3 DMYDay</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DMYDay</code>( <var class="Arg">day</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>converts a number of days, starting 1-Jan-1970, to a list <code class="code">[ day, month, year ]</code> in Gregorian calendar counting.</p>
<p><a id="X7A79DEE07A41B8EF" name="X7A79DEE07A41B8EF"></a></p>
<h5>27.10-4 DayDMY</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DayDMY</code>( <var class="Arg">dmy</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the number of days from 01-Jan-1970 to the day given by <var class="Arg">dmy</var>, which must be a list of the form <code class="code">[ day, month, year ]</code> in Gregorian calendar counting. The result is <code class="keyw">fail</code> on input outside valid ranges.</p>
<p>Note that this makes not much sense for early dates like: before 1582 (no Gregorian calendar at all), or before 1753 in many English speaking countries or before 1917 in Russia.</p>
<p><a id="X87D03FC0809DB6EC" name="X87D03FC0809DB6EC"></a></p>
<h5>27.10-5 WeekDay</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ WeekDay</code>( <var class="Arg">date</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the weekday of a day given by <var class="Arg">date</var>, which can be a number of days since 1-Jan-1970 or a list <code class="code">[ day, month, year ]</code>.</p>
<p><a id="X7C74C33784CDED6C" name="X7C74C33784CDED6C"></a></p>
<h5>27.10-6 StringDate</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringDate</code>( <var class="Arg">date</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>converts <var class="Arg">date</var> to a readable string. <var class="Arg">date</var> can be a number of days since 1-Jan-1970 or a list <code class="code">[ day, month, year ]</code>.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">DayDMY([1,1,1970]);DayDMY([2,1,1970]);</span>
0
1
<span class="GAPprompt">gap></span> <span class="GAPinput">DMYDay(12345);</span>
[ 20, 10, 2003 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">WeekDay([11,3,1998]);</span>
"Wed"
<span class="GAPprompt">gap></span> <span class="GAPinput">StringDate([11,3,1998]);</span>
"11-Mar-1998"
</pre></div>
<p><a id="X84A6A2637FB35A32" name="X84A6A2637FB35A32"></a></p>
<h5>27.10-7 HMSMSec</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ HMSMSec</code>( <var class="Arg">msec</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>converts a number <var class="Arg">msec</var> of milliseconds into a list <code class="code">[ hour, min, sec, milli ]</code>.</p>
<p><a id="X879461D77C81100B" name="X879461D77C81100B"></a></p>
<h5>27.10-8 SecHMSM</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SecHMSM</code>( <var class="Arg">hmsm</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>is the reverse of <code class="func">HMSMSec</code> (<a href="chap27_mj.html#X84A6A2637FB35A32"><span class="RefLink">27.10-7</span></a>).</p>
<p><a id="X802469C47F886A59" name="X802469C47F886A59"></a></p>
<h5>27.10-9 StringTime</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ StringTime</code>( <var class="Arg">time</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>converts <var class="Arg">time</var> (given as a number of milliseconds or a list <code class="code">[ hour, min, sec, milli ]</code>) to a readable string.</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">HMSMSec(Factorial(10));</span>
[ 1, 0, 28, 800 ]
<span class="GAPprompt">gap></span> <span class="GAPinput">SecHMSM([1,10,5,13]);</span>
4205013
<span class="GAPprompt">gap></span> <span class="GAPinput">StringTime([1,10,5,13]);</span>
" 1:10:05.013"
</pre></div>
<p><a id="X870A71D47B0E936E" name="X870A71D47B0E936E"></a></p>
<h5>27.10-10 SecondsDMYhms</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ SecondsDMYhms</code>( <var class="Arg">DMYhms</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>returns the number of seconds from 01-Jan-1970, 00:00:00, to the time given by <var class="Arg">DMYhms</var>, which must be a list of the form <code class="code">[ day, month, year, hour, minute, second ]</code>. The remarks on the Gregorian calendar in the section on <code class="func">DayDMY</code> (<a href="chap27_mj.html#X7A79DEE07A41B8EF"><span class="RefLink">27.10-4</span></a>) apply here as well. The last three arguments must lie in the appropriate ranges.</p>
<p><a id="X78AF8EA887532B5B" name="X78AF8EA887532B5B"></a></p>
<h5>27.10-11 DMYhmsSeconds</h5>
<div class="func"><table class="func" width="100%"><tr><td class="tdleft"><code class="func">‣ DMYhmsSeconds</code>( <var class="Arg">secs</var> )</td><td class="tdright">( function )</td></tr></table></div>
<p>This is the inverse function to <code class="func">SecondsDMYhms</code> (<a href="chap27_mj.html#X870A71D47B0E936E"><span class="RefLink">27.10-10</span></a>).</p>
<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">SecondsDMYhms([ 9, 9, 2001, 1, 46, 40 ]);</span>
1000000000
<span class="GAPprompt">gap></span> <span class="GAPinput">DMYhmsSeconds(-1000000000);</span>
[ 24, 4, 1938, 22, 13, 20 ]
</pre></div>
<p><a id="X78024C8087F3E07F" name="X78024C8087F3E07F"></a></p>
<h4>27.11 <span class="Heading">Obtaining LaTeX Representations of Objects</span></h4>
<p>For the purpose of generating LaTeX source code with <strong class="pkg">GAP</strong> it is recommended to add new functions which will print the LaTeX source or return LaTeX strings for further processing.</p>
<p>An alternative approach could be based on methods for the default LaTeX representation for each appropriate type of objects. However, there is no clear notion of a default LaTeX code for any non-trivial mathematical object; moreover, different output may be required in different contexts.</p>
<p>While customisation of such an operation may require changes in a variety of methods that may be distributed all over the library, the user will have a clean overview of the whole process of LaTeX code generation if it is contained in a single function. Furthermore, there may be kinds of objects which are not detected by the method selection, or there may be a need in additional parameters specifying requirements for the output.</p>
<p>This is why having a special purpose function for each particular case is more suitable. <strong class="pkg">GAP</strong> provides several functions that produce LaTeX strings for those situations where this is nontrivial and reasonable. A useful example is <code class="func">LaTeXStringDecompositionMatrix</code> (<a href="chap71_mj.html#X83EC921380AF9B3B"><span class="RefLink">71.11-5</span></a>) from the <strong class="pkg">GAP</strong> library, others can be found entering <code class="code">?LaTeX</code> at the <strong class="pkg">GAP</strong> prompt. Package authors are encouraged to add an index entry <code class="code">LaTeX</code> to the documentation of all LaTeX string producing functions. This way, entering <code class="code">?LaTeX</code> will give an overview of all documented functionality in this direction.</p>
<div class="chlinkprevnextbot"> <a href="chap0_mj.html">[Top of Book]</a> <a href="chap0_mj.html#contents">[Contents]</a> <a href="chap26_mj.html">[Previous Chapter]</a> <a href="chap28_mj.html">[Next Chapter]</a> </div>
<div class="chlinkbot"><span class="chlink1">Goto Chapter: </span><a href="chap0_mj.html">Top</a> <a href="chap1_mj.html">1</a> <a href="chap2_mj.html">2</a> <a href="chap3_mj.html">3</a> <a href="chap4_mj.html">4</a> <a href="chap5_mj.html">5</a> <a href="chap6_mj.html">6</a> <a href="chap7_mj.html">7</a> <a href="chap8_mj.html">8</a> <a href="chap9_mj.html">9</a> <a href="chap10_mj.html">10</a> <a href="chap11_mj.html">11</a> <a href="chap12_mj.html">12</a> <a href="chap13_mj.html">13</a> <a href="chap14_mj.html">14</a> <a href="chap15_mj.html">15</a> <a href="chap16_mj.html">16</a> <a href="chap17_mj.html">17</a> <a href="chap18_mj.html">18</a> <a href="chap19_mj.html">19</a> <a href="chap20_mj.html">20</a> <a href="chap21_mj.html">21</a> <a href="chap22_mj.html">22</a> <a href="chap23_mj.html">23</a> <a href="chap24_mj.html">24</a> <a href="chap25_mj.html">25</a> <a href="chap26_mj.html">26</a> <a href="chap27_mj.html">27</a> <a href="chap28_mj.html">28</a> <a href="chap29_mj.html">29</a> <a href="chap30_mj.html">30</a> <a href="chap31_mj.html">31</a> <a href="chap32_mj.html">32</a> <a href="chap33_mj.html">33</a> <a href="chap34_mj.html">34</a> <a href="chap35_mj.html">35</a> <a href="chap36_mj.html">36</a> <a href="chap37_mj.html">37</a> <a href="chap38_mj.html">38</a> <a href="chap39_mj.html">39</a> <a href="chap40_mj.html">40</a> <a href="chap41_mj.html">41</a> <a href="chap42_mj.html">42</a> <a href="chap43_mj.html">43</a> <a href="chap44_mj.html">44</a> <a href="chap45_mj.html">45</a> <a href="chap46_mj.html">46</a> <a href="chap47_mj.html">47</a> <a href="chap48_mj.html">48</a> <a href="chap49_mj.html">49</a> <a href="chap50_mj.html">50</a> <a href="chap51_mj.html">51</a> <a href="chap52_mj.html">52</a> <a href="chap53_mj.html">53</a> <a href="chap54_mj.html">54</a> <a href="chap55_mj.html">55</a> <a href="chap56_mj.html">56</a> <a href="chap57_mj.html">57</a> <a href="chap58_mj.html">58</a> <a href="chap59_mj.html">59</a> <a href="chap60_mj.html">60</a> <a href="chap61_mj.html">61</a> <a href="chap62_mj.html">62</a> <a href="chap63_mj.html">63</a> <a href="chap64_mj.html">64</a> <a href="chap65_mj.html">65</a> <a href="chap66_mj.html">66</a> <a href="chap67_mj.html">67</a> <a href="chap68_mj.html">68</a> <a href="chap69_mj.html">69</a> <a href="chap70_mj.html">70</a> <a href="chap71_mj.html">71</a> <a href="chap72_mj.html">72</a> <a href="chap73_mj.html">73</a> <a href="chap74_mj.html">74</a> <a href="chap75_mj.html">75</a> <a href="chap76_mj.html">76</a> <a href="chap77_mj.html">77</a> <a href="chap78_mj.html">78</a> <a href="chap79_mj.html">79</a> <a href="chap80_mj.html">80</a> <a href="chap81_mj.html">81</a> <a href="chap82_mj.html">82</a> <a href="chap83_mj.html">83</a> <a href="chap84_mj.html">84</a> <a href="chap85_mj.html">85</a> <a href="chap86_mj.html">86</a> <a href="chap87_mj.html">87</a> <a href="chapBib_mj.html">Bib</a> <a href="chapInd_mj.html">Ind</a> </div>
<hr />
<p class="foot">generated by <a href="http://www.math.rwth-aachen.de/~Frank.Luebeck/GAPDoc">GAPDoc2HTML</a></p>
</body>
</html>