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

/ StringChapter / Cookbook.AligningStrings

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

Aligning Strings

Problem

You want to align a string, left, right, or center. You might use this when generating reports, for example.

Solution

The easiest solution is in SRFI-13, which solves the left and right padding issues.

500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

string-pad and string-pad-right both default to using #\space (the space character) as the padding character; you may override this by providing the character in the third argument. Both functions also truncate the string provided if it's longer than the specified field width. There's no definition for string-pad-center, though this is one way to do it: 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

This function returns a string of a minimum width equal to the length of a-string. If the width argument minus (string-length a-string) is odd, the extra blank space will be put on the right side of a-string. And, as with the other string-pad functions, it will truncate a-string if it's shorter than width, in this case, it will truncate on the right, e.g. 500 Can't connect to 127.0.0.1:8778 (connect: Connection refused)

Contributors

-- GordonWeakliem - 05 Apr 2004

Comments

CookbookForm
TopicType: Recipe
ParentTopic: StringRecipes
TopicOrder: 120

 
 
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