Re: Re: trimming a string
- To: mathgroup at smc.vnet.net
- Subject: [mg50884] Re: [mg50873] Re: [mg50861] trimming a string
- From: DrBob <drbob at bigfoot.com>
- Date: Sun, 26 Sep 2004 05:31:45 -0400 (EDT)
- References: <200409250555.BAA05042@smc.vnet.net> <opsevjb0t7iz9bcq@monster.cox-internet.com>
- Reply-to: drbob at bigfoot.com
- Sender: owner-wri-mathgroup at wolfram.com
Here's one more solution. One of the others required ReplaceRepeated and the other needed Split; this avoids both. I'm not sure which of the three is fastest. s=" abcdefgh "; StringJoin[Characters@s/.{" "..,x__}/;First@{x}!=" "->{x} /.{x__," "..}/;Last@{x}!=" "->{x}]//FullForm "abcdefgh" Bobby On Sat, 25 Sep 2004 03:32:14 -0500, DrBob <drbob at bigfoot.com> wrote: > s=" abcdefgh "; > StringJoin[Characters@s//.{{" "..,x__}->{x},{x__," "..}->{x}}]//FullForm > > "abcdefgh" > > or > > StringJoin@Flatten[Split@Characters@s/.{{" "..},x__}->{x}/.{x__,{" "..}}->{x}]//FullForm > > "abcdefgh" > > Bobby > > On Sat, 25 Sep 2004 01:55:13 -0400 (EDT), David Park <djmp at earthlink.net> wrote: > >> Akos, >> >> One method... >> >> trimString[s_String] := >> Module[{ss = s}, >> While[First@Characters[ss] === " ", ss = StringDrop[ss, 1]]; >> While[Last@Characters[ss] === " ", ss = StringDrop[ss, -1]]; >> ss] >> >> s = " abcdefgh "; >> trimString[s] // FullForm >> "abcdefgh" >> >> David Park >> djmp at earthlink.net >> http://home.earthlink.net/~djmp/ >> >> >> From: Akos Beleznay [mailto:abeleznay at equitas-capital.com] To: mathgroup at smc.vnet.net >> >> I would appreciate if somebody could show me a simple way of trimming a >> string. (I did it a hard way, but suspect an elegant solution.) >> >> Trim(a_string): returns a copy of a string without leading and trailing >> spaces. >> >> thanks for your help, >> >> Akos Beleznay >> Equitas Capital Advisors LLC >> 909 Poydras Street >> Suite 1850 >> New Orleans, LA 70112 >> Phone: (504) 569-9607 >> Fax: (504) 569-9650 >> abeleznay at equitas-capital.com >> >> >> This email is intended for the sole use of the intended recipient(s) and may >> contain confidential or privileged information. No one is authorized to copy >> or re-use this email or any information contained in it. If you are not the >> intended recipient, we request that you please notify us by reply email and >> destroy all copies of the message and any attachments. PAFA reserves the >> right to monitor and review the content of all e-mail communications sent >> and/or received by its affiliates. Thank you for your cooperation. >> >> >> >> >> >> > > > -- DrBob at bigfoot.com www.eclecticdreams.net
- References:
- Re: trimming a string
- From: "David Park" <djmp@earthlink.net>
- Re: trimming a string