s c h e m a t i c s : c o o k b o o k

/ StringChapter / Cookbook.StringBasics

This Web


WebHome 
WebChanges 
TOC (with recipes)
NewRecipe 
WebTopicList 
WebStatistics 

Other Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
Sourceforge Page
SchemeWiki.org
Original Cookbook
RSS

Scheme Links


Schemers.org
Scheme FAQ
R5RS
SRFIs
Scheme Cross Reference
PLT Scheme SISC
Scheme48 SCM
MIT Scheme scsh
JScheme Kawa
Chicken Guile
Bigloo Tiny
Gambit LispMe
GaucheChez

Lambda the Ultimate
TWiki.org

String Basics

In Scheme, literal strings are enclosed in quotes. According to R5RS, "A string constant may continue from one line to the next, but the exact contents of such a string are unspecified.", probably to account for platform differences in handling newlines. The PLT and mzScheme interpreters allow you to write string literals with linebreaks inline, i.e. 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

R5RS provides the string->list and list->string functions to convert between strings and lists: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

If you want to find out what character is at a specific position in a string, use (string-ref string *i*), where i is a 0-based index in the string: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

string-length will tell you how long a string is. 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

You may have heard that Scheme provides mutable strings. If you want to modify a string in place, the string-set! function will do that for you. However, if you gave the string as a literal to the REPL, string-set! will give you a surprise: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

You can make a copy of a string using string-copy. This will yield a mutable string: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

You can allocate a new string with make-string. make-string comes in 2 forms, the second allows you to specify an initial character: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

You can also use string-append to join strings. This 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

R5RS provides a number of useful string functions, but you should also be aware of SRFI 13 (String Library) and SRFI-14 (Character Set Library), which add a number of very useful functions.

-- GordonWeakliem - 05 Apr 2004

CookbookForm
TopicType: Recipe
ParentTopic: StringRecipes
TopicOrder: 010

 
 
Copyright © 2004 by the contributing authors. All material on the Schematics Cookbook web site is the property of the contributing authors.
The copyright for certain compilations of material taken from this website is held by the SchematicsEditorsGroup - see ContributorAgreement & LGPL.
Other than such compilations, this material can be redistributed and/or modified under the terms of the GNU Lesser General Public License (LGPL), version 2.1, as published by the Free Software Foundation.
Ideas, requests, problems regarding Schematics Cookbook? Send feedback.
/ You are Main.guest