The Mathematica Journal
Volume 9, Issue 3

Search

In This Issue
Articles
Tricks of the Trade
In and Out
Trott's Corner
New Products
New Publications
Calendar
News Bulletins
New Resources
Letters
Classifieds

Download This Issue 

About the Journal
Editorial Policy
Staff and Contributors
Submissions
Subscriptions
Advertising
Back Issues
Contact Information

In and Out
Edited by Paul Abbott

String Trimming

Q: How can I trim a string, such as

in order to remove leading and trailing spaces?

A: Bobby Treat (drbob@bigfoot.com) writes: One way is to use Characters and StringJoin.

Brian Higgins (bghiggins@ucdavis.edu) writes: Another way to achieve your goal is to use the trim method in Java via J/Link.

At www.higgins.ucdavis.edu/Jlink.php there are various examples of integrating Java with Mathematica, including one that makes use of the Java regex (regular expressions) package that is useful for more complicated string manipulations.

In Mathematica 5.1, you also have the ability to work with regular expressions or use StringReplace. This trims white space off ends of strings.



     
About Mathematica | Download Mathematica Player
© Wolfram Media, Inc. All rights reserved.