An interpreted programming language written in Go.
string exposes a String class that can be used to manipulate strings.
To use: import 'std/string'
Returns if string s contains sub-string substr.
Returns the number of non-overlapping instances of substr in s. Count will throw if substr is empty.
dedup will reduce any consecutive substring of char to a single occurrence of char. char must be a single character.
Example:
let strings = module('strings.so')
strings.dedup("name: John", " ") == "name: John"
This example replaces consecutive strings of spaces with a single space.
Format inserts values into the string s. {} is used to mark a replacement. Replacements are done
in order by args.
import "string"
const formatted = string.format("My name is {} and I'm {} years old", "John", 25)
formatted == "My name is John and I'm 25 years old"
Returns if the string begins with prefix.
Returns if the string ends with suffix.
Returns a copy of s with the first n non-overlapping instances of old replaced by new. If old is an empty string, replace will throw an exception. If n < 0, all instances of old are replaced.
Shorthand for splitN(s, sep, -1).
splitN will split s on sep and return at most n array elements. If n is < 0, all substrings will be returned.
If n > 0, at most n substrings will be returned. If n == 0, an empty array is returned.
The returned array may have less than n elements.
trimSpace removes any whitespace characters from the beginning and end of the string.
The initializer takes a string literal.
str: string - The string.Returns if string s contains sub-string substr.
Returns the number of non-overlapping instances of substr in s. Count will throw if substr is empty.
dedup will reduce any consecutive substring of char to a single occurrence of char. char must be a single character.
import "string"
const str = new string.String("Hello")
const dedupped = str.dedup("l")
dedupped == "Helo"
Format inserts values into the string. {} is used to mark a replacement. Replacements are done
in order by args.
import "string"
const str = new string.String("My name is {} and I'm {} years old")
const formatted = str.format("John", 25)
formatted == "My name is John and I'm 25 years old"
Returns if the string begins with prefix.
Returns if the string ends with suffix.
Returns a copy of s with the first n non-overlapping instances of old replaced by new. If old is an empty string, replace will throw an exception. If n < 0, all instances of old are replaced.
Shorthand for splitN(sep, -1).
splitN will split str on sep and return at most n array elements. If n is < 0, all substrings will be returned.
If n > 0, at most n substrings will be returned. The returned array may have less than n elements.
trimSpace removes any whitespace characters from the beginning and end of the string.