The Mathematica Journal
Volume 9, Issue 3


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

Download This Issue 

About the Journal
Editorial Policy
Staff and Contributors
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 ( writes: One way is to use Characters and StringJoin.

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

At 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.