<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" language="JavaScript">
function reDo() {
if (innerWidth != origWidth || innerHeight != origHeight)
location.reload();
}
if ((parseInt(navigator.appVersion) == 4) && (navigator.appName == "Netscape")) {
origWidth = innerWidth;
origHeight = innerHeight;
onresize = reDo;
}
onerror = null;
</script>
<style type="text/css">
< !-- div.WebHelpPopupMenu {
position: absolute;
left: 0px;
top: 0px;
z-index: 4;
visibility: hidden;
}
p.WebHelpNavBar {
text-align: right;
}
-->
</style>
<script type="text/javascript">
gRootRelPath = "../../..";
gCommonRootRelPath = "../../..";
gTopicId = "9.2.9";
<script type="text/javascript" src="../../../template/scripts/rh.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/common.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topic.min.js"></script>
<script type="text/javascript" src="../../../template/scripts/topicwidgets.min.js"></script>
<script type="text/javascript" src="../../../whxdata/projectsettings.js"></script>
<link rel="stylesheet" type="text/css" href="../../../template/styles/topic.min.css"/>
<link rel="stylesheet" type="text/css" href="../../../template/Charcoal_Grey/topicheader.css"/>
<meta name="topic-status" content="Draft"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Strings</title>
<meta name="generator" content="Adobe RoboHelp 2019"/>
<link rel="stylesheet" href="../../../assets/css/default.css" type="text/css"/>
<meta name="rh-authors" content="Mark Alexander"/>
<meta name="topic-comment" content="Reference section for string functions"/>
<meta name="rh-index-keywords" content="\r,\b,\f,\t,\v,\\,\a,\u,\x,\,\r,\b,\f,\t,\v,\\,\a,\u,\x,\"/>
<meta name="search-keywords" content="Strings,\n,\r,\b,\f,\t,\v,\\,\a,\u,\x,\,string literal,@"/>
</head>
<body>
<div class="topic-header rh-hide" id="rh-topic-header" onclick="rh._.goToFullLayout()">
<div class="logo">
</div>
<div class="nav">
<div class="title" title="Strings">
<span>Strings</span>
</div>
<div class="gotohome" title="Click here to see this page in full context">
<span>Click here to see this page in full context</span>
</div>
</div>
</div>
<div class="topic-header-shadow rh-hide" id="rh-topic-header-shadow"></div>
<h1>Strings</h1>
<p>At some time when making your game you will need to use text. Text in games is dealt with by using the <b>string</b> functions (a string is just another way of saying a line of text) and GameMaker Studio 2 has a complete set of functions that
permit you to manipulate strings in many ways, including the insertion of one string in another, the copying of strings and the ability to parse strings for the digits or the letters that they contain. In general a string can <i>only</i> be created
by adding text within double quotes " " and <em>single quote strings are not accepted</em>, nor can you split the string over multiple lines and expect GameMaker Studio 2 to render it as if the line breaks were newlines (unless a
<strong>string literal</strong> <span class="inline">@</span> identifier is used, as explained below).</p>
<p>It is worth noting that there are certain conventions that you can use when creating strings, mostly concerned with using <i>escape characters</i>. These are characters that are preceded by a "<span class="inline">\</span>" symbol. So, for
example, if you wanted to put quotation marks within a string you would have something like this:</p>
<p class="code">str = "Hello\"World\"";</p>
<p>GameMaker Studio 2 also has full four byte wide Unicode character support, allowing you to decode and encode Unicode characters in the upper bounds of the standard (including - but not limited to - emoji). To deal with Unicode characters, you
can use the "<span class="inline">\</span>" to precede any Unicode literal - digits of hex preceded a "<span class="inline">u</span>", for example "<span class="inline"><tt>\u00e2</tt></span>" for "á"- where
the digits are the number of the Unicode character. When working with Unicode in this way, you need to be aware of the fact that GameMaker Studio 2 will interpret <i>all</i> digits following the "<span class="inline">u</span>", so
if you wanted to write "áa" for example, you should use:</p>
<p class="code">"\u00e2\a"</p>
<p>or</p>
<p class="code">"\u00e2\u61"</p>
<p>or</p>
<p class="code">"\u00e2" + "a"</p>
<p>as just using "<tt>\u00e2a</tt>" would actually result in the Unicode character "<tt>ส</tt>" (essentially becoming "<tt>\ue2a</tt>").<i></i></p>
<p>GameMaker Studio 2 can also handle any hexadecimal literal - normally written as digits of hex following "<span class="inline">0x</span>", for example "<span class="inline">0xff</span>", where the digits are the number of
the character to use. In GameMaker Studio 2 these are written using "<tt>\x</tt>" and then the hex value. These and other predefined escape characters are listed in the table below:</p>
<table>
<tbody>
<tr>
<th>Constant</th>
<th>Description</th>
</tr>
<tr>
<td>\n</td>
<td>Newline</td>
</tr>
<tr>
<td>\r</td>
<td>Carriage return</td>
</tr>
<tr>
<td>\b</td>
<td>Backspace (0x08)</td>
</tr>
<tr>
<td>\f</td>
<td>Form Feed (0x0c)</td>
</tr>
<tr>
<td>\t</td>
<td>Horizontal Tab (0x09)</td>
</tr>
<tr>
<td>\v</td>
<td>Vertical Tab (0x0b)</td>
</tr>
<tr>
<td>\\</td>
<td>Backslash itself (0x5c)</td>
</tr>
<tr>
<td>\a</td>
<td>Alert (0x07)</td>
</tr>
<tr>
<td>\u[Hex Digits]</td>
<td>Insert Unicode character</td>
</tr>
<tr>
<td>\x[Hex Digits]</td>
<td>Insert hex literal character</td>
</tr>
<tr>
<td>\[Octal Digits]</td>
<td>Insert octal Unicode character</td>
</tr>
</tbody>
</table>
<p> </p>
<p class="note"><b>NOTE</b>: Strings support form feed, vertical tab etc... but this does not mean to say that <b>rendering</b> does, and when drawing strings these characters may be ignored.</p>
<p>You can also create verbatim <i>string literals</i> by preceding the whole string with the <span class="inline">@</span> character:</p>
<p class="code">var test = @"<br/> Line breaks<br/> over multiple<br/> lines
<br/> ";
</p>
<p>The above code will render the string over multiple lines as if there was a line break escape character included. A verbatim string literal is similar to previous GameMaker version string literals but they also use double or single quotes and must be
prefixed by an <span class="inline">@</span> symbol, they can be broken over multiple lines in the code file and they DO NOT support escaped characters i.e. <span class="inline">@"Hello\World"</span> will <em>not</em> try to escape the W
on World and will be stored verbatim. Note though that when using string literals like this, you will need to break the string if you wish to include quotation marks as part of the string, ie:</p>
<p class="code">var test = @"Hello " + "\"" + @"World" + "\""</p>
<p>Another thing to note is that the Unicode character 9647 (▯) is used to substitute any missing glyphs that you may have in your designated font when rendering it in the draw event. So if your font doesn't have, for example, the ° symbol, then writing
90° will actually produce 90▯.</p>
<p>The following list of functions are all for dealing with strings:</p>
<p> </p>
<ul class="colour">
<li><a href="ansi_char.htm">ansi_char</a></li>
<li><a href="chr.htm">chr</a></li>
<li><a href="ord.htm">ord</a></li>
<li><a href="real.htm">real</a></li>
<li><a href="string.htm">string</a></li>
<li><a href="string_byte_at.htm">string_byte_at</a></li>
<li><a href="string_byte_length.htm">string_byte_length</a></li>
<li><a href="string_set_byte_at.htm">string_set_byte_at</a></li>
<li><a href="string_char_at.htm">string_char_at</a></li>
<li><a href="string_ord_at.htm">string_ord_at</a></li>
<li><a href="string_copy.htm">string_copy</a></li>
<li><a href="string_count.htm">string_count</a></li>
<li><a href="string_delete.htm">string_delete</a></li>
<li><a href="string_digits.htm">string_digits</a></li>
<li><a href="string_format.htm">string_format</a></li>
<li><a href="string_insert.htm">string_insert</a></li>
<li><a href="string_length.htm">string_length</a></li>
<li><a href="string_letters.htm">string_letters</a></li>
<li><a href="string_lettersdigits.htm">string_lettersdigits</a></li>
<li><a href="string_lower.htm">string_lower</a></li>
<li><a href="string_pos.htm">string_pos</a></li>
<li><a href="string_pos_ext.htm">string_pos_ext</a></li>
<li><a href="string_last_pos.htm">string_last_pos</a></li>
<li><a href="string_last_pos_ext.htm">string_last_pos_ext</a></li>
<li><a href="string_repeat.htm">string_repeat</a></li>
<li><a href="string_replace.htm">string_replace</a></li>
<li><a href="string_replace_all.htm">string_replace_all</a></li>
<li><a href="string_upper.htm">string_upper</a></li>
<li><a href="string_height.htm">string_height</a></li>
<li><a href="string_height_ext.htm">string_height_ext</a></li>
<li><a href="string_width.htm">string_width</a></li>
<li><a href="string_width_ext.htm">string_width_ext</a></li>
<li><a href="string_hash_to_newline.htm">string_hash_to_newline</a></li>
<li><a href="../Variable_Functions/is_string.htm">is_string</a></li>
</ul>
<p> </p>
<p>Other than those functions that relate specifically to strings, the <b>Windows</b> target also permits you to use access the clipboard to get and set text information:</p>
<p> </p>
<ul class="colour">
<li><a href="clipboard_has_text.htm">clipboard_has_text</a></li>
<li><a href="clipboard_get_text.htm">clipboard_get_text</a></li>
<li><a href="clipboard_set_text.htm">clipboard_set_text</a></li>
</ul>
<p> </p>
<p> </p>
<p> </p>
<div class="footer">
<div class="buttons">
<div class="clear">
<div style="float:left">Back: <a href="../GML_Reference.htm">GML Reference</a></div>
<div style="float:right">Next: <a href="../Maths_And_Numbers/Maths_And_Numbers.htm">Maths And Numbers</a></div>
</div>
</div>
<h5>© Copyright YoYo Games Ltd. 2020 All Rights Reserved</h5>
</div>
</body></html>