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

/ StringChapter / Cookbook.StringSubstring

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

Accessing Substrings

Problem

You want to extract part of a string.

Solution

R5RS substring is the most general solution. substring takes a string, a start index, and (optionally) an end index. For example: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

substring always allocates a new string.

Discussion

If you have SRFI-13, you may find a more suitable function for getting a substring. First of all, substring/shared may return a string that shares storage with the original argument. SRFI-13 also defines a string-copy that takes start and end arguments, effectively making it a version of substring/shared that always allocates a new string. Finally, if you need to take a substring from the start or end of a string, string-take and string-drop allow you to make a substring by taking or omitting characters from the start of a string. string-take-right and string-drop-right do the same from the end of a string.

-- GordonWeakliem - 22 Apr 2004

CookbookForm
TopicType: Recipe
ParentTopic: StringRecipes
TopicOrder: 030

 
 
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