String
An immutable sequence of characters.
Strings are created with single-quote literals: 'hello'. Concatenate with the comma operator. Compare with =, <, >, <=, >=. Indices are 0-based.
'hello' size >>> 5
'hello', ' world' >>> 'hello world'
'hello' at: 0 >>> $h
"Build a greeting"
| name <String> |
name := 'Maggie'.
'Hello, ', name, '!'
Class Methods
primitives
uncategorized
Return a string containing a single newline character (LF).
Class method — call as String lf.
String lf size >>> 1
Instance Methods
primitives
Parse the receiver as a float.
Parse the receiver as an integer.
Return an FNV-1a hash of the string content.
Print the receiver to stdout.
Print the receiver to stdout followed by a newline.
uncategorized
Return a new string that is the concatenation of the receiver and other.
'hello', ' world' >>> 'hello world'
'', 'abc' >>> 'abc'
'x', '' >>> 'x'
Return true if the receiver sorts before other lexicographically.
Return true if the receiver sorts before or equal to other.
Return true if the receiver and other contain the same characters.
'abc' = 'abc' >>> true
'abc' = 'xyz' >>> false
Return true if the receiver sorts after other lexicographically.
Return true if the receiver sorts after or equal to other.
Return a new string with all characters converted to lowercase.
'HELLO' asLowercase >>> 'hello'
'Hello World' asLowercase >>> 'hello world'
Return the receiver (strings are already strings).
'hello' asString >>> 'hello'
Return the string as a symbol (interned string).
'hello' asSymbol >>> #hello
Return a new string with all characters converted to uppercase.
'hello' asUppercase >>> 'HELLO'
'Hello World' asUppercase >>> 'HELLO WORLD'
Return the Character at a 0-based index.
'hello' at: 0 >>> $h
'hello' at: 4 >>> $o
Return a substring from start index to the end, 0-based.
'hello' copyFrom: 2 >>> 'llo'
'hello' copyFrom: 0 >>> 'hello'
Return a substring from start (inclusive) to end (exclusive), 0-based.
'hello' copyFrom: 1 to: 4 >>> 'ell'
'hello' copyFrom: 0 to: 5 >>> 'hello'
Evaluate aBlock with each character (as a single-character string).
result := ''.
'abc' do: [:ch | result := result, ch, '-'].
result >>> 'a-b-c-'
Return true if the string ends with the given suffix.
'hello' endsWith: 'llo' >>> true
'hello' endsWith: 'xyz' >>> false
Return true if the string contains the given substring or character.
'hello' includes: 'ell' >>> true
'hello' includes: 'xyz' >>> false
Return the 0-based index of the first occurrence, or -1 if not found.
'hello' indexOf: 'l' >>> 2
'hello' indexOf: 'z' >>> -1
Return true if this single-character string is a letter or digit.
'a' isAlphanumeric >>> true
'5' isAlphanumeric >>> true
' ' isAlphanumeric >>> false
Return true if this single-character string is a digit (0-9).
'5' isDigit >>> true
'a' isDigit >>> false
Return true if the string has no characters.
'' isEmpty >>> true
'a' isEmpty >>> false
Return true if this single-character string is a letter (a-z, A-Z).
'a' isLetter >>> true
'5' isLetter >>> false
Return true if this single-character string is whitespace.
' ' isWhitespace >>> true
'a' isWhitespace >>> false
Return true if the string has at least one character.
'hello' notEmpty >>> true
'' notEmpty >>> false
Return a quoted string representation suitable for display.
'hello' printString >>> '''hello'''
Return a new string with all occurrences of old replaced by new.
'hello world' replaceAll: 'o' with: '0' >>> 'hell0 w0rld'
'aaa' replaceAll: 'a' with: 'bb' >>> 'bbbbbb'
'hello' replaceAll: 'z' with: 'q' >>> 'hello'
'a-b-c' replaceAll: '-' with: '_' >>> 'a_b_c'
Return the number of characters in the string.
'hello' size >>> 5
'' size >>> 0
Split the string by the given separator and return an Array of substrings.
'a,b,c' split: ',' >>> #('a' 'b' 'c' )
'hello' split: 'l' >>> #('he' '' 'o' )
'no-sep' split: ',' >>> #('no-sep' )
Return true if the string starts with the given prefix.
'hello' startsWith: 'hel' >>> true
'hello' startsWith: 'xyz' >>> false
'--key' startsWith: '--' >>> true
Return a copy with leading and trailing whitespace removed.
' hello ' trimBoth >>> 'hello'
'no spaces' trimBoth >>> 'no spaces'