Methods on Values
Every value type in CColon has built-in methods that can be called with dot notation.
int methods
| Method | Description | Returns |
|---|---|---|
.tostring() |
Convert to string representation | string |
.tofloat() |
Convert to float | float |
float methods
| Method | Description | Returns |
|---|---|---|
.tostring() |
Convert to string representation | string |
.toint() |
Truncate to integer | int |
Note that .toint() truncates toward zero, it does not round.
string methods
| Method | Description | Returns |
|---|---|---|
.length() |
Number of characters | int |
.tostring() |
Returns the string itself | string |
.toint() |
Parse as integer | int |
.tofloat() |
Parse as float | float |
var string s = "hello"
console.println(s.length().tostring()) // 5
var string num = "123"
var int parsed = num.toint() // 123
.toint() and .tofloat() produce a runtime error if the string is not a valid number.
String indexing
Individual characters can be accessed by index:
bool methods
| Method | Description | Returns |
|---|---|---|
.tostring() |
Convert to "true" or "false" |
string |
list methods
| Method | Description | Returns |
|---|---|---|
.length() |
Number of elements | int |
.append(v) |
Add element to end | nil |
.pop() |
Remove and return last element | value |
.tostring() |
String representation | string |
See Lists and Arrays for details.
array methods
| Method | Description | Returns |
|---|---|---|
.length() |
Number of elements | int |
.tostring() |
String representation | string |
See Lists and Arrays for details.
Chaining methods
Methods can be chained: