Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/GAP/pkg/crystcat/grp/   (Algebra von RWTH Aachen Version 4.15.1©)  Datei vom 25.0.2018 mit Größe 135 kB image not shown  

Quelle  chap27.html   Sprache: unbekannt

 
<?xml version="1.0" encoding="UTF-8"?>

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

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


<div class="chlinktop"><span class="chlink1">Goto Chapter: </span><a href="chap0.html">Top</a>  <a href="chap1.html">1</a>  <a href="chap2.html">2</a>  <a href="chap3.html">3</a>  <a href="chap4.html">4</a>  <a href="chap5.html">5</a>  <a href="chap6.html">6</a>  <a href="chap7.html">7</a>  <a href="chap8.html">8</a>  <a href="chap9.html">9</a>  <a href="chap10.html">10</a>  <a href="chap11.html">11</a>  <a href="chap12.html">12</a>  <a href="chap13.html">13</a>  <a href="chap14.html">14</a>  <a href="chap15.html">15</a>  <a href="chap16.html">16</a>  <a href="chap17.html">17</a>  <a href="chap18.html">18</a>  <a href="chap19.html">19</a>  <a href="chap20.html">20</a>  <a href="chap21.html">21</a>  <a href="chap22.html">22</a>  <a href="chap23.html">23</a>  <a href="chap24.html">24</a>  <a href="chap25.html">25</a>  <a href="chap26.html">26</a>  <a href="chap27.html">27</a>  <a href="chap28.html">28</a>  <a href="chap29.html">29</a>  <a href="chap30.html">30</a>  <a href="chap31.html">31</a>  <a href="chap32.html">32</a>  <a href="chap33.html">33</a>  <a href="chap34.html">34</a>  <a href="chap35.html">35</a>  <a href="chap36.html">36</a>  <a href="chap37.html">37</a>  <a href="chap38.html">38</a>  <a href="chap39.html">39</a>  <a href="chap40.html">40</a>  <a href="chap41.html">41</a>  <a href="chap42.html">42</a>  <a href="chap43.html">43</a>  <a href="chap44.html">44</a>  <a href="chap45.html">45</a>  <a href="chap46.html">46</a>  <a href="chap47.html">47</a>  <a href="chap48.html">48</a>  <a href="chap49.html">49</a>  <a href="chap50.html">50</a>  <a href="chap51.html">51</a>  <a href="chap52.html">52</a>  <a href="chap53.html">53</a>  <a href="chap54.html">54</a>  <a href="chap55.html">55</a>  <a href="chap56.html">56</a>  <a href="chap57.html">57</a>  <a href="chap58.html">58</a>  <a href="chap59.html">59</a>  <a href="chap60.html">60</a>  <a href="chap61.html">61</a>  <a href="chap62.html">62</a>  <a href="chap63.html">63</a>  <a href="chap64.html">64</a>  <a href="chap65.html">65</a>  <a href="chap66.html">66</a>  <a href="chap67.html">67</a>  <a href="chap68.html">68</a>  <a href="chap69.html">69</a>  <a href="chap70.html">70</a>  <a href="chap71.html">71</a>  <a href="chap72.html">72</a>  <a href="chap73.html">73</a>  <a href="chap74.html">74</a>  <a href="chap75.html">75</a>  <a href="chap76.html">76</a>  <a href="chap77.html">77</a>  <a href="chap78.html">78</a>  <a href="chap79.html">79</a>  <a href="chap80.html">80</a>  <a href="chap81.html">81</a>  <a href="chap82.html">82</a>  <a href="chap83.html">83</a>  <a href="chap84.html">84</a>  <a href="chap85.html">85</a>  <a href="chap86.html">86</a>  <a href="chap87.html">87</a>  <a href="chapBib.html">Bib</a>  <a href="chapInd.html">Ind</a>  </div>

<div class="chlinkprevnexttop"> <a href="chap0.html">[Top of Book]</a>   <a href="chap0.html#contents">[Contents]</a>    <a href="chap26.html">[Previous Chapter]</a>    <a href="chap28.html">[Next Chapter]</a>   </div>

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

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

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

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

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

<h5>27.1-1 IsChar</h5>

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




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

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

<h5>27.1-2 IsString</h5>

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

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



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


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

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

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

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


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

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

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

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

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


<div class="example"><pre>
<span class="GAPprompt">gap></span> <span class="GAPinput">s4:= "abc\"def\nghi";;

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


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

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


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

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

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

<p>There are a number of <em>special character sequences</em> that can be used between the singlequotes of a character literal or between the doublequotes of a string literal to specify characters. They consist of 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">\"
<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">\'
<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.html#X7AFA64D97A1F39A3"><span class="RefLink">6.3-4</span></a>), <code class="func">PrintTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>), or <code class="func">AppendTo</code> (<a href="chap9.html#X86956C577FFEE1F9"><span class="RefLink">9.8-3</span></a>) send the characters directly to the output stream.</p>


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

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

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

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

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


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

<p>Triple quoted strings are represented internally identically to all other strings, they only provide an alternative method of giving strings to GAP. Triple quoted strings still follow GAP's line editing rules (6.2), which state that in normal line editing mode, lines starting gap> , > or brk> will have this beginning part removed.



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

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

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

<h5>27.4-1 IsStringRep</h5>

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

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

<h5>27.4-2 ConvertToStringRep</h5>

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

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

<h5>27.4-3 CopyToStringRep</h5>

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

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

<h5>27.4-4 IsEmptyString</h5>

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


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

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

<h5>27.4-5 EmptyString</h5>

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

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

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

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

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

<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.html#X7A274A1F8553B7E6"><span class="RefLink">4.13</span></a> for the details.</p>

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

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

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

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

<h5>27.7-1 DisplayString</h5>

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

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

<h5>27.7-2 DEFAULTDISPLAYSTRING</h5>

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

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

<h5>27.7-3 ViewString</h5>

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

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

<h5>27.7-4 DEFAULTVIEWSTRING</h5>

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

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

<h5>27.7-5 PrintString</h5>

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

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

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


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

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

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

<h5>27.7-6 String</h5>

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

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

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


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

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

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

<h5>27.7-7 StripLineBreakCharacters</h5>

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

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

<h5>27.7-8 HexStringInt</h5>

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

<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.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.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.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.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."
--> --------------------

--> maximum size reached

--> --------------------

100%


[ Verzeichnis aufwärts0.16unsichere Verbindung  Übersetzung europäischer Sprachen durch Browser  ]