string (type)

See also: string.lib


Strings are one of the basic types of np, together with numbers, booleans, nil, and lists. Since strings in np are binary-safe, they can contain any combination of bytes, including Unicode characters. However, string behaviors currently don't respect the byte boundaries of Unicode code points.

String Literals

There are multiple options to express a string literal in np.

String Symbols

The string symbol notation is for short alphanumeric strings without any other characters.

print( #shortString )

Quoted String Literals

You can use either single or double quotes to make a string:

new string1 = 'look at me'

String literals can have line breaks in them:

new string2 = 'at the age old pond
a frog leaps into water
a deep resonance'


Another way to build a string is to use double square brackets:

[[this is also a string]]

Double squares can also be extended by inserting one or more equals signs (=) in between them, for example to allow for nested brackets inside the string itself:

[=[this is a string with [[brackets]] inside]=]

Concatenating Strings

To chain two or more strings together, use the concat operator << or its mutable variant <<=:

print( 'Somewhere' << 'Over' << 'The' << 'Rainbow' )

Numbers and strings can be concatenated together into strings:

print( 99 << ' bottles of beer on the wall' )

String Behavior

String objects come with their own built-in behaviors as defined in the string library.