Strings


Purpose

Strings are one of the primitive expression types in Scheme. A string is a series of zero or more characters, spaces, and numbers, surrounded by double quotes.

Usage

When a string is evaluated, it returns that string.

Examples

Strings evaluate to themselves.
  ox --> "sam"
  sam
  ox --> "Big 'ole bag of dirt"
  "Big 'ole bag of dirt"
Strings are most frequently used for file and shader names.

There are several convenient functions for dealing with strings.

Strings can be converted to and from other primitive data types:

  ox --> (number->string 5)
  "5"
  ox --> (string->number "17")
  17

  ox --> (string->symbol "spam")
  spam
  ox --> (symbol->string 'spam)
  "spam"
Strings can be compared to one another for equality:
  ox --> (string=? "hi" "low")
  ()
  ox --> (string=? "blah" "blah")
  t
Strings can be strung together to make bigger strings:
  ox --> (string-append "Tasha" " " "ate all my" " cookies")
  "Tasha ate all my cookies"
String length can be determined:
  ox --> (string-length "And so it goes")
  14
Individual characters in a string can be referenced (remember, the first character is number zero!):
  ox --> (string-ref "Big Nose" 2)
  "g"
Return to Scheme Introduction
mrl