Re: trimming a string
- To: mathgroup at smc.vnet.net
- Subject: [mg50925] Re: trimming a string
- From: rolf at mertig.com (Rolf Mertig)
- Date: Tue, 28 Sep 2004 00:58:36 -0400 (EDT)
- References: <ADVMAIL6UC9y3jVON3s00006792@advisormail.net> <cj634g$qon$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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
- Follow-Ups:
- Re: Re: trimming a string
- From: DrBob <drbob@bigfoot.com>
- Re: Re: trimming a string