NexuScript 1.5
Text
Building and searching text.
Turns any values into text and joins them together.
Syntax
string(value::Any...) -> StringParameters
| Name | Type | Default | Description |
|---|---|---|---|
value | Anyany number | required | The 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))
endprint(string("Up bar: ", close > open))See also
The same text in capital letters.
Syntax
uppercase(s::String) -> StringParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The 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"))
endSee also
The same text in small letters.
Syntax
lowercase(s::String) -> StringParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The 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))
endSee also
Tests whether one text appears anywhere inside another.
Syntax
contains(s::String, part::String) -> BoolParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The text to search in. |
part | String | required | The 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))
endSee also
Tests whether a text begins with another text.
Syntax
startswith(s::String, part::String) -> BoolParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The text to check. |
part | String | required | The 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))
endSee also
Tests whether a text ends with another text.
Syntax
endswith(s::String, part::String) -> BoolParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The text to check. |
part | String | required | The 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))
endSee also
The position where one text first appears inside another.
Syntax
find(s::String, part::String) -> NumberParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The text to search in. |
part | String | required | The 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
A piece of a text, from one position to another.
Syntax
slice(s::String, first::Number, last::Number) -> StringParameters
| Name | Type | Default | Description |
|---|---|---|---|
s | String | required | The text to take a piece of. |
first | Number | required | The position of the first character to keep, counting from 1. |
last | Number | required | The 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))
endSee also
How many characters are in a text, or how many items are in an array.
Syntax
length(x::Any) -> NumberParameters
| Name | Type | Default | Description |
|---|---|---|---|
x | Any | required | A 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
- NS210
xis 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