Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

steel/strings

Strings in Steel are immutable, fixed length arrays of characters. They are heap allocated, and are implemented under the hood as referenced counted Rust Strings. Rust Strings are stored as UTF-8 encoded bytes.

char->integer

Returns the Unicode codepoint of a given character.

(char->integer char?) -> integer?

Examples

> (char->integer #\a) ;; => 97
> (char->integer #\λ) ;; => 955

char->number

Attemps to convert the character into an ascii decimal digit, and returns #f on failure.

(char->number char?) -> (or/c number? bool?)

Examples

> (char->number #\4) ;; => 4
> (char->number #\a) ;; => #f
> (char->number #\٣) ;; => #f

char-ci<=?

Returns #t if the characters are monotonically non-decreasing according to their codepoints, in a case-insensitive fashion (as if char-foldcase was applied to the arguments).

(char-ci<=? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char-ci<=? #\a #\b) ;; => #t
> (char-ci<=? #\a #\B) ;; => #t
> (char-ci<=? #\a #\B #\c) ;; => #t
> (char-ci<=? #\a #\B #\b) ;; => #t

char-ci<?

Returns #t if the characters are monotonically increasing according to their codepoints, in a case-insensitive fashion (as if char-foldcase was applied to the arguments).

(char-ci<? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char-ci<? #\a #\b) ;; => #t
> (char-ci<? #\a #\B) ;; => #t
> (char-ci<? #\a #\B #\c) ;; => #t
> (char-ci<? #\a #\B #\b) ;; => #f

char-ci=?

Checks if all characters are equal, in a case-insensitive fashion (i.e. as if char-foldcase was applied to the arguments).

Requires that all inputs are characters, and will otherwise raise an error.

(char-ci=? char1 char2 ...) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char-ci=? #\s #\S) ;; => #t
> (char-ci=? #\ß #\ẞ) ;; => #t
> (char-ci=? #\σ #\Σ #\ς) ;; => #t

char-ci>=?

Returns #t if the characters are monotonically non-increasing according to their codepoints, in a case-insensitive fashion (as if char-foldcase was applied to the arguments).

(char-ci>=? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char-ci>? #\b #\a) ;; => #t
> (char-ci>? #\B #\a) ;; => #t
> (char-ci>? #\c #\B #\a) ;; => #t
> (char-ci>? #\c #\B #\b) ;; => #t

char-ci>?

Returns #t if the characters are monotonically decreasing according to their codepoints, in a case-insensitive fashion (as if char-foldcase was applied to the arguments).

(char-ci>? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char-ci>? #\b #\a) ;; => #t
> (char-ci>? #\B #\a) ;; => #t
> (char-ci>? #\c #\B #\a) ;; => #t
> (char-ci>? #\c #\B #\b) ;; => #f

char-digit?

Returns #t if the character is an ascii decimal digit.

(char-digit? char?) -> bool?

Examples

> (char-digit? #\4) ;; => #t
> (char-digit? #\a) ;; => #f
> (char-digit? #\٣) ;; => #f
> (char-digit? #\①) ;; => #f

char-downcase

Returns the lower case version of a character, if defined by Unicode, or the same character otherwise.

(char-downcase char?) -> char?

Examples

> (char-downcase #\U) ;; => #\u
> (char-downcase #\d) ;; => #\d
> (char-downcase #\ẞ) ;; => #\ß

char-foldcase

Apply simple unicode case-folding to a char

(char-foldcase char?) -> char?

Examples

> (char-foldcase #\A) ;; => #\a
> (char-foldcase #\c) ;; => #\c
> (char-foldcase #\ς) ;; => #\σ

char-upcase

Returns the upper case version of a character, if defined by Unicode, or the same character otherwise.

(char-upcase char?) -> char?

Examples

> (char-upcase #\d) ;; => #\D
> (char-upcase #\U) ;; => #\U
> (char-upcase #\ß) ;; => #\ß

char-whitespace?

Returns #t if the character is a whitespace character.

Example

> (char-whitespace? #\space) ;; => #t
> (char-whitespace? #\newline) ;; => #t
; nbsp character
> (char-whitespace? #\xA0) ;; => #t
> (char-whitespace? #\越) ;; => #f

char<=?

Returns #t if the characters are monotonically non-decreasing according to their codepoints.

(char<=? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char<=? #\a #\b) ;; => #t
> (char<=? #\a #\B) ;; => #f
> (char<=? #\a #\b #\c) ;; => #t
> (char<=? #\a #\b #\b) ;; => #t

char<?

Returns #t if the characters are monotonically increasing according to their codepoints.

(char<? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char<? #\a #\b) ;; => #t
> (char<? #\a #\b #\c) ;; => #t
> (char<? #\a #\b #\b) ;; => #f

char=?

Checks if all characters are equal.

Requires that all inputs are characters, and will otherwise raise an error.

(char=? char1 char2 ...) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char=? #\a #\a) ;; => #t
> (char=? #\a #\b) ;; => #f
> (char=? #\a #\A) ;; => #f

char>=?

Returns #t if the characters are monotonically non-increasing according to their codepoints.

(char>=? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char>=? #\b #\a) ;; => #t
> (char>=? #\c #\b #\a) ;; => #t
> (char>=? #\c #\b #\b) ;; => #t

char>?

Returns #t if the characters are monotonically decreasing according to their codepoints.

(char>? char1 char2 ... ) -> bool?

  • char1 : char?
  • char2 : char?

Examples

> (char>? #\b #\a) ;; => #t
> (char>? #\c #\b #\a) ;; => #t
> (char>? #\c #\b #\b) ;; => #f

ends-with?

Checks if the input string ends with a given suffix

(ends-with? input pattern) -> bool?

  • input : string?
  • pattern: string?

Examples

> (ends-with? "foobar" "foo") ;; => #false
> (ends-with? "foobar" "bar") ;; => #true

int->string

Converts an integer into a string.

Use of this procedure is discouraged in favor of the more powerful and more portable (number->string) procedure.

(int->string int?) -> string?

Examples

> (int->string 10) ;; => "10"

integer->char

Returns the character corresponding to a given Unicode codepoint.

(integer->char integer?) -> char?

Examples

> (integer->char #x61) ;; => #\a
> (integer->char 955) ;; => #\λ

make-string

Creates a string of a given length, filled with an optional character (which defaults to #\0).

(make-string len [char]) -> string?

  • len : int?
  • char : char? = #\0

Examples

> (make-string 5 #\a) ;; => "aaaaa"
> (make-string 5) ;; => "\0\0\0\0\0"

number->string

Converts the given number to a string, with an optional radix.

Returns an error, if the value given is not a number.

(number->string number? [radix]) -> string?

  • radix: number?
> (number->string 10) ;; => "10"
> (number->string 1.0) ;; => "1.0"
> (number->string 1/2) ;; => "1.0"
> (number->string 1+2i) ;; => "1+2i"
> (number->string 255 16) ;; => "ff"
> (number->string 1/2 2) ;; => "1/10"

split-many

Splits a string given a separator pattern into a list of strings.

(split-many str pat) -> (listof string?)

  • str : string?
  • pat : string?

Examples

(split-many "foo,bar,baz" ",") ;; => '("foo" "bar" "baz")
(split-many "foo|bar|" "|") ;; => '("foo" "bar" "")
(split-many "" "&") ;; => '("")

split-once

Splits a string given a separator at most once, yielding a list with at most 2 elements.

(split-once str pat) -> string?

  • str : string?
  • pat : string?

Examples

(split-once "foo,bar,baz" ",") ;; => '("foo" "bar,baz")
(split-once "foo|bar|" "|") ;; => '("foo" "bar|")
(split-once "" "&") ;; => '("")

split-whitespace

Returns a list of strings from the original string split on the whitespace

(split-whitespace string?) -> (listof string?)

Examples

(split-whitespace "apples bananas fruits veggies") ;; '("apples" "bananas" "fruits" "veggies")
(split-whitespace "one\t \ttwo\nthree") ;; '("one" "two" "three")

starts-with?

Checks if the input string starts with a prefix

(starts-with? input pattern) -> bool?

  • input : string?
  • pattern: string?

Examples

> (starts-with? "foobar" "foo") ;; => #true
> (starts-with? "foobar" "bar") ;; => #false

string

Constructs a string from the given characters

(string . char?) -> string?

Examples

> (string #\h #\e #\l #\l #\o) ;; => "hello"
> (string #\λ) ;; => "λ"
> (string) ;; => ""

string->bytes

Encodes a string as UTF-8 into a bytevector.

(string->bytes str [start] [end]) -> bytes?

  • str : string?
  • start : int? = 0
  • end : int? = (string-length str)

Examples

(string->bytes "Apple") ;; => #u8(#x41 #x70 #x70 #x6C #x65)
(string->bytes "αβγ") ;; => #u8(#xCE #xB1 #xCE #xB2 #xCE #xB3)
(string->bytes "one two three" 4 7) ;; => #u8(#x74 #x77 #x6F)

string->int

Converts a string into an int. Raises an error if the string cannot be converted to an integer.

Use of this procedure is discouraged in favor of the more powerful and more portable (string->number) procedure.

(string->int string?) -> int?

Examples

> (string->int "100") ;; => 10
> (string->int "not-an-int") ;; error

string->list

Converts a string into a list of characters.

(string->list str [start] [end]) -> (listof char?)

  • str : string?
  • start : int? = 0
  • end : int? = (string-length str)

Examples

> (string->list "hello") ;; => '(#\h #\e #\l #\l #\o)
> (string->list "one two three" 4 7) ;; => '(#\t #\w #\o)

string->lower

Alias of string-downcase.

string->number

Converts the given string to a number, with an optional radix. On failure, it returns #f

(string->number digits [radix]) -> (or/c number? boolean?)

  • digits : string?
  • radix : number?

Examples

> (string->number "10") ;; => 10
> (string->number "1.0") ;; => 1.0
> (string->number "1/2") ;; => 1/2
> (string->number "1+2i") ;; => 1+2i
> (string->number "ff") ;; => #f
> (string->number "ff" 16) ;; => 255
> (string->number "1/10" 2) ;; => 1/2
> (string->number "not-a-number") ;; => #f

string->symbol

Returns an interned symbol from the given string.

(string->symbol string?) -> symbol?

Examples

> (string->symbol "abc") ;; => 'abc
> (string->symbol "pea pod") ;; => '|pea pod|

string->uninterned-symbol

Return an uninterned symbol from the given string.

(string->uninterned-symbol string?) -> symbol?

Examples

(string->uninterned-symbol "abc") ;; => 'abc
(string->uninterned-symbol "pea pod") ;; => '|pea pod|

string->upper

Alias of string-upcase.

string->utf8

Alias of string->bytes.

string->vector

Returns a vector containing the characters of a given string

(string->vector s [start] [end]) -> vector?

  • str : string?
  • start : int? = 0
  • end : int? = (string-length str)

Examples

(string->vector "hello") ;; => '#(#\h #\e #\l #\l #\o)
(string->vector "one two three" 4 7) ;; => '#(#\t #\w #\o)

string-append

Concatenates all of the given strings into one

(string-append strs...) -> string?

  • strs ... : string?

Examples

> (string-append) ;; => ""
> (string-append "foo" "bar") ;; => "foobar"

string-ci<=?

Compares strings lexicographically (as in"less-than-or-equal"), in a case insensitive fashion.

(string-ci<=? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string-ci<=? "a" "b") ;; => #t
> (string-ci<=? "a" "B") ;; => #t
> (string-ci<=? "a" "B" "c") ;; => #t
> (string-ci<=? "a" "B" "b") ;; => #t
> (string-ci<=? "Straßburg" "STRASSE" "straßenbahn") ;; => #t

string-ci<?

Compares strings lexicographically (as in"less-than"), in a case insensitive fashion.

(string-ci<? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string-ci<? "a" "b") ;; => #t
> (string-ci<? "a" "B") ;; => #t
> (string-ci<? "a" "B" "c") ;; => #t
> (string-ci<? "a" "B" "b") ;; => #f
> (string-ci<? "Straßburg" "STRASSE" "straßenbahn") ;; => #t

string-ci=?

Compares strings for equality, in a case insensitive fashion.

(string-ci=? string? string? ...) -> bool?

Examples

> (string-ci=? "hEllO WorLd" "HELLO worlD") ;; => #t
> (string-ci=? "Straße" "STRASSE" "strasse" "STRAẞE") ;; => #t
> (string-ci=? "ὈΔΥΣΣΕΎΣ" "ὀδυσσεύς" "ὀδυσσεύσ") ;; => #t

string-ci>=?

Compares strings lexicographically (as in"greater-than-or-equal"), in a case insensitive fashion.

(string-ci>=? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string-ci>=? "b" "a") ;; => #t
> (string-ci>=? "B" "a") ;; => #t
> (string-ci>=? "c" "B" "a") ;; => #t
> (string-ci>=? "c" "B" "b") ;; => #f
> (string-ci>=? "straßenbahn" "STRASSE" "Straßburg") ;; => #t

string-ci>?

Compares strings lexicographically (as in"greater-than"), in a case insensitive fashion.

(string-ci>? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string-ci>? "b" "a") ;; => #t
> (string-ci>? "B" "a") ;; => #t
> (string-ci>? "c" "B" "a") ;; => #t
> (string-ci>? "c" "B" "b") ;; => #f
> (string-ci>? "straßenbahn" "STRASSE" "Straßburg") ;; => #t

string-contains?

Searches a string to check if it contains the second argument.

(string-contains? string? string?) -> bool?

Examples

(string-contains? "hello" "lo") ;;=> #t
(string-contains? "hello" "world") ;;=> #f

string-downcase

Creates a new lowercased version of the input string

(string-downcase string?) -> string?

Examples

> (string-downcase "sPonGeBoB tExT") ;; => "spongebob text"
> (string-downcase "ὈΔΥΣΣΕΎΣ") ;; => "ὀδυσσεύς"
> (string-downcase "STRAẞE") ;; => "straße"

string-foldcase

Applies full unicode case-folding to the input string

(string-foldcase string?) -> string?

Examples

> (string-foldcase "Straße") ;; => "strasse"

string-join

Joins the given list of strings, with an optional separator.

(string-join strings [sep]) -> string?

  • strings : (listof string?)
  • sep : string? = ""

Examples

(string-join '("a" "b" "c")) ;; => "abc"
(string-join '("one" "two" "three") ", ") ;; => "one, two, three"

string-length

Get the number of characters in the string.

(string-length string?) -> int?

Examples

> (string-length "apples") ;; => 6
> (string-length "αβγ") ;; => 3
> (string-length "✅") ;; => 1

string-ref

Extracts the nth character out of a given string, starting at 0.

(string-ref str n) -> char?

  • str : string?
  • n : int?
(string-ref "one" 1) ;; => #\n
(string-ref "αβγ" 1) ;; => #\β

string-replace

Replaces all occurrences of a pattern into the given string

(string-replace str from to) -> string?

  • str : string?
  • from : string?
  • to : string?

Examples

(string-replace "hello world" "o" "@") ;; => "hell@ w@rld"

string-upcase

Creates a new uppercased version of the input string

(string-upcase string?) -> string?

Examples

> (string-upcase "lower") ;; => "LOWER"
> (string-upcase "straße") ;; => "STRASSE"

string<=?

Compares strings lexicographically (as in"less-than-equal-to").

(string<=? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string<=? "a" "b") ;; => #t
> (string<=? "a" "b" "c") ;; => #t
> (string<=? "a" "b" "b") ;; => #t

string<?

Compares strings lexicographically (as in"less-than").

(string<? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string<? "a" "b") ;; => #t
> (string<? "a" "b" "c") ;; => #t
> (string<? "a" "b" "b") ;; => #f

string=?

Compares strings for equality.

(string=? string1 string2 ...) -> bool?

  • string1 : string?
  • string2 : string?

Examples

> (string=? "hello" "hello") ;; => #t
> (string=? "hello" "HELLO") ;; => #f

string>=?

Compares strings lexicographically (as in"greater-than-or-equal").

(string>=? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string>=? "b" "a") ;; => #t
> (string>=? "c" "b" "a") ;; => #t
> (string>=? "c" "b" "b") ;; => #t

string>?

Compares strings lexicographically (as in"greater-than").

(string>? s1 s2 ... ) -> bool?

  • s1 : string?
  • s2 : string?

Examples

> (string>? "b" "a") ;; => #t
> (string>? "c" "b" "a") ;; => #t
> (string>? "c" "b" "b") ;; => #f

substring

Creates a substring slicing the characters between two indices.

(substring str start end) -> string?

  • str: string?
  • start : int?
  • end : int?

Examples

(substring "hello" 1 4) ;; => "ell"
(substring "hello" 10 15) ;; => error

to-string

Concatenates all of the inputs to their string representation, separated by spaces.

(to-string xs ...)

  • xs : any/c

Examples

> (to-string 10) ;; => "10"
> (to-string 10 20) ;; => "10 20"
> (to-string "hello" "world") ;; => "hello world"

trim

Returns a new string with the leading and trailing whitespace removed.

(trim string?) -> string?

Examples

> (trim "   foo     ") ;; => "foo"

trim-end

Returns a new string with the trailing whitespace removed.

(trim string?) -> string?

Examples

> (trim "   foo     ") ;; => "   foo"

trim-end-matches

Returns a new string with the given pat repeatedly removed from the end of the string

(trim-end-matches string? string?) -> string?

Examples

> (trim-end-matches "123foo1bar123123" "123") ;; => "123foo1bar"

trim-start

Returns a new string with the leading whitespace removed.

(trim string?) -> string?

Examples

> (trim "   foo     ") ;; => "foo     "

trim-start-matches

Returns a new string with the given pat repeatedly removed from the start of the string

(trim-start-matches string? string?) -> string?

Examples

> (trim-start-matches "123foo1bar123123" "123") ;; => "foo1bar123123"

utf8-length

Get the length of the string in UTF-8 bytes.

(utf8-length string?) -> int?

Examples

> (utf8-length "apples") ;; => 6
> (utf8-length "αβγ") ;; => 6
> (utf8-length "✅") ;; => 3