-
Notifications
You must be signed in to change notification settings - Fork 0
utils.string.wren
clsource edited this page Nov 10, 2020
·
6 revisions
Simple string functions. Some code was based on Recto.wren library.
- Example:
import "domepunk/utils/string" for Str
- Since: 1.0.0
Creates a new String object
- Signature: construct new(string:String) -> Str
- Since: 1.0.0
- Parameter string: A string object
Limits string length (or less) characters from the string. This is safer than using slices since it would not throws if the number of characters available is less than the picked length.
- Signature: limit(length:Num) -> Str
- Since: 1.0.0
- Example:
// returns: hello
Str.new("hello wren").limit(5)
- Parameter length: How many characters to limit
- Returns: a new string with the specified length characters.
Reverses a string value.
- Signature: reverse() -> Str
- Since: 1.0.0
- Example:
// returns: "olleh"
Str.new("hello").reverse()
// also available as static
Str.reverse("hello")
// and a property
Str.new("hello").toReverse
- Returns: a reversed string
Convert a string to lowercase.
- Signature: lower() -> Str
- Since: 1.0.0
- Example:
// Result is "camelcaseisawesome!"
Str.new("camelCaseIsAwesome!").lower().toString
// Also available as a static method
Str.lower("camelCaseIsAwesome!")
// and a property
Str.new("hello").toLowerCase
- Returns: The lowercased string
Convert a string to uppercase
- Signature: upper() -> Str
- Since: 1.0.0
- Example:
// Result is "CAMELCASEISAWESOME!"
Str.new("camelCaseIsAwesome!").upper().toString
// Also available as a static method
Str.upper("camelCaseIsAwesome!")
// and a property
Str.new("hello").toUpperCase
- Returns: The uppercased string
Uppercase the first letter in each word. Title Case.
- Signature: title() -> Str
- Since: 1.0.0
- Example:
// Result is "The Unicorn Prances"
Str.new("the unicorn prances").title().toString
// Or using the static method
Str.title("the unicorn prances")
// and a property
Str.new("hello").toTitleCase
- Returns: The updated string.
Convert a character to its numeric ASCII value This only works with a single character. This works with the extended ASCII table (0 - 255).
- Signature: static toOrd(chr:String) -> Num
- Since: 1.0.0
- Example:
// Result is 33 as Num
Str.toOrd("!")
- Parameter chr: The character to convert.
- Returns: The numeric ASCII value it represents.
Convert a numeric ASCII value to its character This only works with a single number. This works with the extended ASCII table (0 - 255).
- Signature: static toChr(ord:Num) -> String
- Since: 1.0.0
- Example:
// Result is "!"
Str.toChr(33)
- Parameter ord: The ASCII numeric value to convert.
- Returns: A string of the character it represents.