Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: trimming a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg50952] Re: [mg50925] Re: trimming a string
  • From: DrBob <drbob at bigfoot.com>
  • Date: Wed, 29 Sep 2004 03:15:20 -0400 (EDT)
  • References: <ADVMAIL6UC9y3jVON3s00006792@advisormail.net> <cj634g$qon$1@smc.vnet.net> <200409280458.AAA24031@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

My post explains the problem with RepeatedNull. You need a test that b (or r) starts with a non-blank.

Bobby

On Tue, 28 Sep 2004 00:58:36 -0400 (EDT), Rolf Mertig <rolf at mertig.com> wrote:

> Here is another (fast) suggestion, including tabs and newline characters.
> The code code be simpler if I could get the pattern ... (RepeatedNull) to
> work.
> Maybe someone knows how to do this.
>
> Chomp::usage="Chomp[string] chops initial and final white space of string.";
> (*Chomp removes initial and final empty spaces*)
> SetAttributes[Chomp, Listable];
> Chomp[""] = Chomp[" "] = "";
> Chomp[s_] := StringJoin @@ Flatten[Split[
>  Characters[s]] //. {
>  {      {(" " | "\t" | "\n" | "\r" | "\[IndentingNewLine]") ..}, b___,
>         {(" " | "\n" | "\t" | "\r" | "\[IndentingNewLine]") ..}} :> {b},
>        {{(" " | "\n" | "\t" | "\r" | "\[IndentingNewLine]") ..}, r___} :> {r},
>  {a___, {(" " | "\n" | "\t" | "\r" | "\[IndentingNewLine]") ..}} :> {a} }]
>
>
>
> Rolf Mertig
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Hyperbolic function identity
  • Next by Date: Newbie question about the behavior of NMaximize
  • Previous by thread: Re: trimming a string
  • Next by thread: help on Rewrite rules