Entry
string.join() vs % and operators
Jul 5th, 2000 09:59
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 96, Darrell
"""
Packages: basic_datatypes.strings
"""
"""
We have an application where many thousands of small strings are to be
inserted and deleted from a very large buffer.
When you have 100k different small strings to replace in 4meg of text the
string.join seems to work well.
"""
def insertDeleteList(inbuf, l):
""" Insert and delete segments in a buffer
l is a list of (start, string, end) The input 'l' must be sorted
If start and end are equal then string is inserted at that point
If end > start then this range is deleted.
If end < start then this range is duplicated
"""
splitBuf=[]
last=0
for i in l:
b=inbuf[last:i[0]]
splitBuf.append(b)
splitBuf.append(i[1])
last=i[2] # Advance past some buffer here
splitBuf.append(inbuf[last:])
return string.join(splitBuf,'')