| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Scripting 3.4. String variables</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 |
Scripting 3.4. String variables |
| 13 |
</b></font></table></table> |
| 14 |
<p>Just as you can store <a href="Scripting_3_2__Numeric_variables.html">numeric variables</a>, you can store <i>string variables</i>, which contain text instead of numbers. Here is an example:</p> |
| 15 |
<code> word1$ = “Hello”<br></code> |
| 16 |
<code> word2$ = “world”<br></code> |
| 17 |
<code> sentence$ = word1$ + “ ” + word2$<br></code> |
| 18 |
<code> writeInfoLine: “The whole sentence is: ”, sentence$<br></code> |
| 19 |
<p>Yes, this is another way to get the sentence <code><font size=+1>Hello world</font></code> into the Info window. It's a more linguistically valid way to do it, and here is how it works:</p> |
| 20 |
<dl> |
| 21 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">1. In line 1, the value “Hello”, which is a text (as we can see by its use of quotes), is stored into the variable <i><code><font size=+1>word1$</font></code></i>, which is a string variable (as we can see because its name ends in a dollar sign).</dd> |
| 22 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">2. In line 2, the text value “world” is stored into the string variable <i><code><font size=+1>word2$</font></code></i>.</dd> |
| 23 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">3. In line 3, we have the formula <code><font size=+1>word1$ + “ ” + word2$</font></code>, which contains two variables, namely <i><code><font size=+1>word1$</font></code></i> and <i><code><font size=+1>word2$</font></code></i>.</dd> |
| 24 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">4. The values of the two variables are “Hello” and “world”, respectively, so what the formula actually says is “Hello” + “ ” + “world”.</dd> |
| 25 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">5. The pluses in the formula mean “concatenate”, so we concatenate the three strings “Hello”, “ ”, and “world”, giving the longer string “Hello world”.</dd> |
| 26 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">6. Still in line 3, the string value “Hello world” is assigned to the string variable <i><code><font size=+1>sentence$</font></code></i>.</dd> |
| 27 |
<dd style="position:relative;padding-left:1em;text-indent:-2em">7. Line 4 reports in the Info window: <code><font size=+1>The whole sentence is: Hello world</font></code></dd> |
| 28 |
</dl> |
| 29 |
<h3>Links to this page</h3> |
| 30 |
<ul> |
| 31 |
<li><a href="Scripting.html">Scripting</a> |
| 32 |
<li><a href="Scripting_3__Simple_language_elements.html">Scripting 3. Simple language elements</a> |
| 33 |
<li><a href="Scripting_5_1__Variables.html">Scripting 5.1. Variables</a> |
| 34 |
</ul> |
| 35 |
<hr> |
| 36 |
<address> |
| 37 |
<p>© ppgb 20130411</p> |
| 38 |
</address> |
| 39 |
</body> |
| 40 |
</html> |