MathGroup Archive 2001

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

Search the Archive

Re: Manipulating Strings

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28268] Re: Manipulating Strings
  • From: "Rasmus Debitsch" <debitsch at zeiss.de>
  • Date: Sat, 7 Apr 2001 03:44:27 -0400 (EDT)
  • References: <9ajmoi$sav@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

StringJoin@@First/@Split[Characters[string]]

implements the same function as squash.

Regards
--

        Rasmus Debitsch
        Carl Zeiss Lithos GmbH
        Carl Zeiss Strasse
        D-73447 Oberkochen

        eMail : debitsch at zeiss.de

"Brian Higgins" <bghiggins at ucdavis.edu> schrieb im Newsbeitrag
news:9ajmoi$sav at smc.vnet.net...
> Dear Math group,
>
> I have a string with runs of repeated characters and  want to  replace
> sequences of repeated characters with a single character. For example
> consider the string
>
> "CLKJLDiCXLklJDMXLKJdLmxLLLEIKXMDLKJcMDLKJXMeNNlB"
> Thus I want a function that will take the groups "LLL" and "NN" in the
> above string and replace them with "L" and "N".
>
> Now I have been able to devise such a function but it seems pretty
> clunky, and I was wondering if anyone had a better idea tha made use
> of StringMatchQ to do the same task. Here is my method
>
> squash[str_String] := Module[{repeatCharList, repeatPattern,
> repeatChar},
>     repeatCharList =
>       Select[Split[Characters[proteinString2]], Length[#] > 1 &];
>     repeatPattern = Apply[StringJoin, repeatCharList, 1];
>     repeatChar = Map[First, repeatCharList];
>     StringReplace[str, Thread[repeatPattern -> repeatChar]]]
>
> Thanks much,
>
> Brian
>
>




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