Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*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 2001

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

Search the Archive

Re: Re: Manipulating Strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28279] Re: [mg28259] Re: Manipulating Strings
  • From: Mianlai Zhou <lailai at carmen.nikhef.nl>
  • Date: Sat, 7 Apr 2001 03:44:37 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I have a much better way to realize it (squash repeated letters in the
string) :

mysquash[str_String] :=
   StringJoin[ Characters[str] //. {a___, x_?LetterQ, x_, b___} :> {a, x, b} ]

Is it a acceptable approach?

Mianlai Zhou
NIKHEF, Amsterdam

On Fri, 6 Apr 2001, Brian Higgins wrote:

>  I have made some improvements on my original function. It now handles
> arbitrary length sequence of characters:
>
> squash3[str_String] := Module[{SeqRule},
>     SeqRule =
>       Join[Thread[
>           Map[# <> # &, CharacterRange["a", "z"]] ->
>             CharacterRange["a", "z"]],
>         Thread[Map[# <> # &, CharacterRange["A", "Z"]] ->
>             CharacterRange["A", "Z"]]];
>     FixedPoint[StringReplace[#, SeqRule] &, str]]
>
> Still seems a bit clunky. Any ideas how this may be further improved.
>
> Brian
>



  • Prev by Date: Re: Howto vonvert a list of functions in a list valued function
  • Next by Date: Re: Saving sound waveforms
  • Previous by thread: Manipulating Strings
  • Next by thread: Re: Manipulating Strings