ProtoLang.net

Reference: String

☰ Hide Sidebar
TOKEN STRING
ALIAS STR

The String Data Type is used to represent text. All strings must appear inside Text / " delimiters and are limited to Printable ASCII Characters only. Strings can be combined with the Concatenate / .. operator along with Booleans, Integers or Floats to create Expressions. Special Note: The Double Quote ( " ) symbol is currently not allowed inside strings.

Syntax

The short syntax structure uses the word STR:

NEW STR VARIABLE = VALUE

The long syntax structure uses the word STRING:

NEW STRING VARIABLE EQUAL TO VALUE

Examples

Example: Creating String and setting Value to Literal

NEW STR x = "Hello World!"
PRINTLN x // Displays "Hello World!"

Example: Creating String and setting Value to Variable

NEW STR x = "Hello World!"
NEW STR y = x
PRINTLN y // Displays "Hello World!"

Example: Creating String and setting Value to Expression using Concatenate operator

NEW STR a = "Hello"
NEW STR b = " "
NEW STR c = "World!"
PRINTLN a .. b .. c // Displays "Hello World!"

Example: Creating String and setting Value to Expression with Boolean, Integer and Float using Concatenate operator

NEW BOOL a = TRUE
NEW INT b = 1
NEW FLOAT c = 1.0
NEW STR d = a .. b .. c
PRINTLN d // Displays "TRUE11.0"

Common Errors

Error: Creating String and setting to Boolean Literal

NEW STR x = TRUE // Runtime error! Cannot assign Boolean Literal to String Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating String and setting to Integer Literal

NEW STR x = 1 // Runtime error! Cannot assign Integer Literal to String Data Type
PRINTLN x // This line is not executed because the program crashed!

Error: Creating String and setting to Float Literal

NEW STR x = 1.0 // Runtime error! Cannot assign Float Literal to String Data Type
PRINTLN x // This line is not executed because the program crashed!