Definition of STRING
A STRING is a data type used to store text, it is not a primitive variable such as int, bool or float, but a set of primitive variables of the character type.
Syntax of STRING data in Unity
Unity simplifies the syntax of string data and makes it possible to treat it as if it were a primitive variable. To define a string data, use the keyword “string” followed by a name, for example as follows:
string aString;
String data are specified using double quotes, for example:
aString = “A generic text.”;
Using the reference of a string, its size can be accessed using the dot operator and the word “Length“, as follows:
aString.Length;
The execution of the above instruction results in an integer value corresponding to the number of characters contained in the string.
Applications of a STRING data type in Unity
String variables allow us to store texts, so we can use them to store names, descriptions, texts that appear in the user interface. When saving data using PlayerPrefs in Unity you must indicate strings that will be used as keys to access the saved information.