38 lines
1.2 KiB
Plaintext
38 lines
1.2 KiB
Plaintext
From: bwizard at bga.com (Purple)
|
|
Date: Sun, 25 Apr 1999 23:01:34 GMT
|
|
Subject: Handling backspace chars in a string...
|
|
Message-ID: <37239c48.594910176@news2.bga.com>
|
|
X-UID: 1686
|
|
|
|
I'm in the posistion of having to process strings with arbitrary
|
|
numbers of backspace and newline characters in them. The backspaces
|
|
actually get put in the string, so I have to handle removing the
|
|
characters that are backspaced over. Currently I'm doing this
|
|
something like this (hastily retyped mostly from memory so forgive any
|
|
small errors and/or typos) :
|
|
|
|
i = len(str)
|
|
while ktr < i:
|
|
if string[ktr] == '\b':
|
|
bBegin = ktr
|
|
backs = 0
|
|
while string[ktr] == '\b':
|
|
backs = backs + 1
|
|
ktr = ktr + 1
|
|
if backs > (ktr - backs - 1): # backs > prior chars
|
|
string = string[bBegin+backs:]
|
|
ktr = 0
|
|
else:
|
|
string = string[:bBegin-backs] + string[ktr:]
|
|
ktr = bBegin - backs
|
|
i = len(str)
|
|
ktr = ktr + 1
|
|
|
|
This just looked rather messy to me -- I was curious if anyone know a
|
|
better way?
|
|
|
|
|
|
|
|
|
|
|