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
- References:
- Re: trimming a string
- From: rolf@mertig.com (Rolf Mertig)
- Re: trimming a string