Difference between revisions of "SHIP:Data Types:String"

From Serious Documentation
Jump to: navigation, search
(Created page with "== See Also == * SHIP Text Model Reference * SHIP Language Support * {{Node|string|string}} and {{Node|text|text}} nodes == Summar...")
 
(Examples)
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== See Also ==
 
== See Also ==
 +
* [[SHIP:Data_Types|All Data Types]]
 +
 
* SHIP [[SHIP:TextModel|Text Model Reference]]
 
* SHIP [[SHIP:TextModel|Text Model Reference]]
 
* SHIP [[SHIP:Language_Support|Language Support]]
 
* SHIP [[SHIP:Language_Support|Language Support]]
 
* {{Node|string|string}} and {{Node|text|text}} nodes
 
* {{Node|string|string}} and {{Node|text|text}} nodes
== Summary ==
+
* SHIP [[SHIP:Sail:Functions#String_Functions|Sail String Functions]]
The {{DataType|String}} data type is a sequence of UTF8 characters terminated in an implicit end-of-string character.
+
 
 +
== {{DataType|String}} ==
 +
<onlyinclude>Stings in SHIP are a sequence of UTF8 characters terminated in an implicit end-of-string character.
 +
{{DataTypeTableStart|}}
 +
|{{DataType|String}}||A sequence of UTF8 characters terminated in an implicit end-of-string character.
 +
|}</onlyinclude>
 +
 
 +
{{DataType|String}} constants are written in [[SHIP:Sail|Sail Scripts]] enclosed in double quotes (&quot;), and can be concatenated using the <code>+</code> operator.
 +
 
 +
{{DataType|String}} constants with alternate language translations can be created using {{Node|string|string}} and {{Node|text|text}} nodes in the {{Node|resources|resources}} area.
 +
 
 +
[[SHIP:Sail:Functions#String_Functions|Sail String Functions]] enable you to access the Unicode codepoints within a {{DataType|String}}, count the character length of the {{DataType|String}}, access subsets of the {{DataType|String}}, and more.
 +
 
 +
== Examples ==
 +
This is an example of assigning a {{DataType|String}} constant to a {{Node|text|text}} node within a [[SHIP:Sail|Sail script]]:
 +
 
 +
  <code>text.value = "hello";</code>
 +
 
 +
And this example shows string concatenation:
 +
 
 +
  <code>text.value = "hello" + " " + "there";</code>
 +
 
 +
You can define strings with alternate language translations using {{Node|string|string}} and {{Node|text|text}} nodes.  These translated string resources can be combined at runtime in [[SHIP:Sail|Sail scripts]] to form larger strings, for example if you have a {{Node|string|string}} resource:
 +
 
 +
<code>tWelcome</code>
 +
<code>  enUS: Welcome</code>
 +
<code>  frFR: Bienvenue</code>
 +
 
 +
a [[SHIP:Sail|Sail script]] can combine these using simple concatenation:
 +
 
 +
<code>text.value = tWelcome + " Terry";</code>
 +
 
 +
The <code>text.value</code> will be assigned either <code>Welcome Terry</code> or <code>Bienvenue Terry</code> depending on the value of the {{SysVar|shiplanguage}} system variable at the time of the assignment.  This script can be wrapped in a {{Node|listener|listener}} that is {{Prop|listener|listeningto}} the {{SysVar|shiplanguage}} system variable such that whenever the system language changes, the <code>text.value</code> is automatically updated to the current translation available.

Latest revision as of 05:19, 19 April 2014

See Also

String

Stings in SHIP are a sequence of UTF8 characters terminated in an implicit end-of-string character.

Data Type Description
String A sequence of UTF8 characters terminated in an implicit end-of-string character.

String constants are written in Sail Scripts enclosed in double quotes ("), and can be concatenated using the + operator.

String constants with alternate language translations can be created using string and text nodes in the resources area.

Sail String Functions enable you to access the Unicode codepoints within a String, count the character length of the String, access subsets of the String, and more.

Examples

This is an example of assigning a String constant to a text node within a Sail script:

 text.value = "hello";

And this example shows string concatenation:

 text.value = "hello" + " " + "there";

You can define strings with alternate language translations using string and text nodes. These translated string resources can be combined at runtime in Sail scripts to form larger strings, for example if you have a string resource:

tWelcome
  enUS: Welcome
  frFR: Bienvenue

a Sail script can combine these using simple concatenation:

text.value = tWelcome + " Terry";

The text.value will be assigned either Welcome Terry or Bienvenue Terry depending on the value of the shiplanguage system variable at the time of the assignment. This script can be wrapped in a listener that is listeningto the shiplanguage system variable such that whenever the system language changes, the text.value is automatically updated to the current translation available.