Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: partitioning a string

  • To: mathgroup at smc.vnet.net
  • Subject: [mg60964] Re: [mg60932] partitioning a string
  • From: János <janos.lobb at yale.edu>
  • Date: Wed, 5 Oct 2005 02:28:09 -0400 (EDT)
  • References: <200510040524.BAA17916@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Oct 4, 2005, at 1:24 AM, Sara wrote:

> I have tred to partition a String and iwrote this code but its take  
> to time to run, and it doesnt show eny result.
> stringPartition[s_, n_] := Module[{}, emptyString = Mod[StringLength 
> [s], n];
>     If[emptyString != 0, empt = n - emptyString];
>     str1 := " ";
>     str2 := "";
>     For[i = 1, i <= empt, i++, str2 = str2 <> str1];
>     str = s <> str2;
>     M = StringLength[str];
>     yasList = Range[1, M/n] ;
>     For[i = 1, i <= M, i + n, For[j = 1, j <= M/n, j++,
>           yasList[[j]] = StringTake[i, j*n]
>                ];
>            ];


How about if you convert your string first into Characters and then  
use normal Partition to partition it.  Then at the end you can  
convert the characters back to string with StringJoin[Map 
[ToString,yourlist]]

János


----------------------------------------------
Trying to argue with a politician is like lifting up the head of a  
corpse.
(S. Lem: His Master Voice)


  • Prev by Date: Re: Exporting PNGs with transparent backgroud?
  • Next by Date: Re: partitioning a string
  • Previous by thread: partitioning a string
  • Next by thread: Re: partitioning a string