8.13 Primitive types and structs
The following definitions constitute the types sub-module of the standard library.
They are reflected in types.osc, and are made available via either import osc.standard.types, import osc.standard.all, or import osc.standard statements, as defined in Importing the standard library.
They reside in the stdtypes namespace.
1 String Methods
The standard library provides the following methods on strings in the std namespace:
| Method | Method declaration fragment | Description | Example |
|---|---|---|---|
|
def length() → int |
Returns the length of a string. |
|
|
def contains(substring: string) → bool |
Returns true if a string contains a substring. |
|
|
def substring(start: int, end: int) → string |
Returns a substring of a string. Indexing is zero-based. The start index, is inclusive, the end index, which defaults to the end of the string, is exclusive. Negative indices index from the end of the string, with -1 being the last character of the string. Indices that are out of bounds are silently truncated to be in bounds. |
|
|
def split(separator: string) → list of string |
Splits a string into a list of substrings using the argument as the separator, empty strings are retained. |
|
|
def join(parts: list of string) → string |
Concatenates a list of strings connected by a separator. |
|
|
def replace(old: string, new: string) → string |
Replaces all occurrences of a substring in the string with another substring. |
|
|
def trim() → string |
Removes leading and trailing whitespace from a string. |
|