Skip to content
Nexus Prop LLC

NexuScript 1.5

Text

Building and searching text.

string

functionNexuScript 1.0

Turns any values into text and joins them together.

Syntax

string(value::Any...) -> String

Parameters

NameTypeDefaultDescription
valueAnyany numberrequiredThe values to write as text, in order. Give as many as you like, or none for empty text.

Returns

String All the values written as text, one after another, with nothing added between them.

Details

Numbers are written in the shortest form that reads back as the same number (0.1, 25000, 1.5e-7). Bools are true or false. Colours are #rrggbb, or #rrggbbaa when not fully opaque, and color.none is none. Arrays are written in square brackets. Writing $(x) inside text does the same thing as string(x).

Missing values

A missing number is written as the word missing.

Examples

if bar.last
    marker(string("Close ", close, " on bar ", bar.index))
end
print(string("Up bar: ", close > open))

See also

Stringprintmarker

uppercase

functionNexuScript 1.0

The same text in capital letters.

Syntax

uppercase(s::String) -> String

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to change.

Returns

String A copy of s with every letter in upper case.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing".

Example

if bar.last
    marker(uppercase("last close"))
end

See also

lowercasestring

lowercase

functionNexuScript 1.0

The same text in small letters.

Syntax

lowercase(s::String) -> String

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to change.

Returns

String A copy of s with every letter in lower case.

Details

Handy before comparing text typed by a user, so "ES" and "es" match.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing".

Example

if bar.last
    marker(lowercase(symbol.root))
end

See also

uppercasecontains

contains

functionNexuScript 1.0

Tests whether one text appears anywhere inside another.

Syntax

contains(s::String, part::String) -> Bool

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to search in.
partStringrequiredThe text to look for.

Returns

Bool true when part appears in s. An empty part is always found.

Details

Capital and small letters count as different. Use lowercase on both sides to ignore case.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing".

Example

if contains(symbol.description, "Nasdaq")
    background(color.fade(color.blue, 90))
end

See also

startswithendswithfind

startswith

functionNexuScript 1.0

Tests whether a text begins with another text.

Syntax

startswith(s::String, part::String) -> Bool

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to check.
partStringrequiredThe beginning to look for.

Returns

Bool true when s begins with part. An empty part always matches.

Details

Capital and small letters count as different.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing".

Example

if startswith(symbol.ticker, "NQ")
    background(color.fade(color.teal, 90))
end

See also

endswithcontains

endswith

functionNexuScript 1.0

Tests whether a text ends with another text.

Syntax

endswith(s::String, part::String) -> Bool

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to check.
partStringrequiredThe ending to look for.

Returns

Bool true when s ends with part. An empty part always matches.

Details

Capital and small letters count as different.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing".

Example

if endswith(symbol.ticker, "6")
    background(color.fade(color.purple, 90))
end

See also

startswithcontains

find

functionNexuScript 1.2

The position where one text first appears inside another.

Syntax

find(s::String, part::String) -> Number

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to search in.
partStringrequiredThe text to look for.

Returns

Number The position of the first part in s, counting from 1. 0 when it is not there, and 1 when part is empty.

Details

Positions count the same way as length, so most characters count as one and some emoji count as two. Capital and small letters count as different.

Missing values

Text is never missing. An empty text, "", is the closest thing to "nothing". The result is a whole number, never missing.

Errors

  • NS232the script starts with a header older than nexscript 1.2

Example

plot("Where the Z is", find(symbol.ticker, "Z"))

See also

slicecontainslength

slice

functionNexuScript 1.2

A piece of a text, from one position to another.

Syntax

slice(s::String, first::Number, last::Number) -> String

Parameters

NameTypeDefaultDescription
sStringrequiredThe text to take a piece of.
firstNumberrequiredThe position of the first character to keep, counting from 1.
lastNumberrequiredThe position of the last character to keep. It is included.

Returns

String The characters from first to last, both included. Empty text when last is before first.

Details

You cannot go out of bounds: a first below 1 starts at 1, and a last past the end stops at the end. Fractions are dropped, so 2.9 counts as 2. slice(s, find(s, part), length(s)) keeps everything from part on.

Missing values

A missing first or last gives empty text.

Errors

  • NS232the script starts with a header older than nexscript 1.2

Example

if bar.last
    marker(slice(symbol.ticker, 1, 2))
end

See also

findlengthstring

length

functionNexuScript 1.0

How many characters are in a text, or how many items are in an array.

Syntax

length(x::Any) -> Number

Parameters

NameTypeDefaultDescription
xAnyrequiredA text or an array of any type.

Returns

Number The number of characters in a text, or the number of items in an array. 0 when it is empty.

Details

This one function works on both text and arrays. For text, most characters count as one and some emoji count as two.

Missing values

Never missing. A missing number inside an array still counts as an item.

Errors

  • NS210x is something other than text or an array

Examples

plot("Ticker length", length(symbol.ticker))
state recent::Array{Number} = []
on bar
    push!(recent, close)
    if length(recent) > 10
        popfirst!(recent)
    end
    plot("Closes kept", length(recent))
end

See also

isemptysliceArray