MathGroup Archive 2000

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

Search the Archive

Re: working with large strings.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21658] Re: working with large strings.
  • From: Bojan Bistrovic <bojanb at physics.odu.edu>
  • Date: Fri, 21 Jan 2000 04:00:09 -0500 (EST)
  • Organization: Old Dominion Universityaruba
  • References: <86156m$jsj@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

dustin wrote:
> 
> If you want to write a program that alters elements of very large lists
> you can alter single elements with
> 
> largelist[[elementnumber]]=newvalue;
> 
> However, if you want to do this with a large string you have to do
> something like
> 
> largestring=StringTake[largestring,{1,elementnumber-1}]<>newvalue<>StringTake[largestring,{1,elementnumber+1}];
> 
> The problem with this is it requires making a whole new copy of the
> string to change just one element.  This will really slow a program down
> if you are working with large strings or have to repeat the process many
> times.
> 
> Does anyone know a way around this?
> 
> Dustin Soodak

You could try using

largestring=StringReplacePart[largestring,newvalue,{elementnumber,x}]

where "x" would be 1 in your case (if you want to replace just one
element of the string. I'm not sure how it works internally, does it
involve large copying or not. The other option is to convert the 
string to a list and then work with the list:

largelist=Characters[largestring]
largelist[[elementnumber]]=newvalue
largestring=StringJoin@@largelist

The last one isn't worth the trouble if you just need to do the
replacement once, but if your problem involves a lot of replacements,
you might want to work with the list instead (if the nature of your
problem allows, of course)

Bye, Bojan

-- 
-------------------------------------------------------------
Bojan Bistrovic,                       bojanb at physics.odu.edu  
Old Dominion University, Physics Department,      Norfolk, VA
-------------------------------------------------------------


  • Prev by Date: Corrupted notebook
  • Next by Date: Re: InterpolatingFunction in NDSolve
  • Previous by thread: working with large strings.
  • Next by thread: Re: working with large strings.