From: bwizard at bga.com (Purple)
Date: Mon, 26 Apr 1999 01:15:32 GMT
Subject: Handling backspace chars in a string...
References: <37239c48.594910176@news2.bga.com> <000301be8f7e$16b89780$669e2299@tim>
Message-ID: <3723bd8c.603427371@news2.bga.com>
Content-Length: 1333
X-UID: 1262                                                  

On Mon, 26 Apr 1999 00:45:32 GMT, "Tim Peters" <tim_one at email.msn.com>
wrote:

>[Purple]
>> I'm in the poistion of having to process strings with arbitrary
>> numbers of backspace and newline characters in them.
>
>Your code doesn't appear to care about newlines one way or t'other.  Do you
><wink>?

I didn't post the code for that bit as it seems easy enough to take
care of processing those with something like
map(string.strip,string.split(stringWithNewlines,"\n")

Unless there's a better way to do that too? :)

>> The backspaces actually get put in the string, so I have to handle
>> removing the characters that are backspaced over.
>> ... [rather sprawling string + indexing code] ...
>> This just looked rather messy to me -- I was curious if anyone know a
>> better way?
>
>Assuming "better" means "less messy" here, lists support appending and
>deleting quite naturally and efficiently; like
>
[code using lists snipped]

>This essentially treats the input string as a sequence of opcodes for a
>stack machine, where "\b" means "pop" and anything else means "push me!".
>
>don't-use-any-indices-and-you-can't-screw-'em-up<wink>-ly y'rs  - tim

I may well go that route... Is it any slower or faster to do this
using lists rather than counting up the backspaces and slicing around
the bits that need to be snipped?





