Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Strings

NaijaScript strings are UTF-8 encoded and support Unicode characters.

Literals

Declare string values:

make foo get "Aisha"
make bar get " hello "

Concatenation and interpolation

Concatenate with add and interpolate with braces:

make foo get "Hello, " add "Aisha" add "!"
make bar get "Hello, {foo}!"

Methods

Available methods and return types:

MethodDescriptionReturns
len()Number of Unicode code points in the stringNumber
slice(start, end)Substring from start (inclusive) to end (exclusive). start/end are floored; negative indexes count from end.String
to_uppercase()Convert to uppercaseString
to_lowercase()Convert to lowercaseString
find(needle)Index of first occurrence (0-based). Returns -1 if not found.Number
replace(old, new)Replace all occurrences of old with newString
trim()Remove leading and trailing whitespaceString
to_number()Parse the string as a number, or NaN on failureNumber