{ STRING type variables } — Programming theory

Definition of STRING

A STRING is a data type used to store text, it is not a prim­i­tive vari­able such as int, bool or float, but a set of prim­i­tive vari­ables of the char­ac­ter type.

Here is a more detailed arti­cle about what are vari­ables in pro­gram­ming and the dif­fer­ent types of vari­ables.




Syntax of STRING data in Unity

Uni­ty sim­pli­fies the syn­tax of string data and makes it pos­si­ble to treat it as if it were a prim­i­tive vari­able. To define a string data, use the key­word "string" fol­lowed by a name, for exam­ple as follows:

string aString;

String data are spec­i­fied using dou­ble quotes, for example:

aString = "A gener­ic text.";

Using the ref­er­ence of a string, its size can be accessed using the dot oper­a­tor and the word "Length", as follows:


The exe­cu­tion of the above instruc­tion results in an inte­ger val­ue cor­re­spond­ing to the num­ber of char­ac­ters con­tained in the string.

Applications of a STRING data type in Unity

String vari­ables allow us to store texts, so we can use them to store names, descrip­tions, texts that appear in the user inter­face. When sav­ing data using Play­er­Prefs in Uni­ty you must indi­cate strings that will be used as keys to access the saved information.

Scroll to Top
Secured By miniOrange