simple string backspace question

V

vedrandekovic

Hello,

I have one simple string, backspace character question.Here is my
example:
"HelloBSworld"

Should this character "\b" (backspace) in this text return this:
"Helloworld"?





Regards,
Vedran
 
L

Lawrence Oluyede

"HelloBSworld"

Should this character "\b" (backspace) in this text return this:
"Helloworld"?

rhymes@groove ~ % python Python
2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.Hellworld

What system are u using?
 
V

vedrandekovic

Hello,

I have one simple string, backspace character question.Here is my
example:


"HelloBSworld"

Should this character "\b" (backspace) in this text return this:
"Helloworld"?

Regards,
Vedran

Hi,

If you mean on operating system then unfortunately Windows XP.

Regards,
Vedran
 
L

Lawrence Oluyede

If you mean on operating system then unfortunately Windows XP.

I don't know for sure but maybe it doesn't support all ASCII escapes
codes.

Why do you care about \b anyway :) ?
 
V

vedrandekovic

I don't know for sure but maybe it doesn't support all ASCII escapes
codes.

Why do you care about \b anyway :) ?

--
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair

Hi,

I need this inevitable for my "programming language", for code
indentation. I don't know how to write script with module tokenize
for code indentation.

Regards,
Vedran
 
D

Diez B. Roggisch

Hi,

I need this inevitable for my "programming language", for code
indentation. I don't know how to write script with module tokenize
for code indentation.

Still not giving up reinventing the wheel? You should take some lessons on
syntax analysis before attempting this. But I know this words won't be
heard...

So, to your actual problem: that backspace is removing a character is
something an editor or a terminal do, because they interpret the backspace.
You wouldn't expect the string "<font color="blue">foo</font>" to be
rendered blue by magic as well, wouldn't you?

So what you need to do is: search the string for backspaces, and remove the
BS as well as the character before. Something along these lines (untested):

teststring = "abc\bcde\b"

while teststring.find("\b") > -1:
pos = teststring.find("\b")
teststring = teststring[:pos-1] + teststring[pos+1:]


Diez
 
J

John Machin

Hi,

If you mean on operating system then unfortunately Windows XP.

Point (1) Works on Windows XP for me:

C:\junk>ver

Microsoft Windows XP [Version 5.1.2600]

C:\junk>\python25\python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
or, for mild amusement:
.... sys.stdout.write("|/-\\"[x & 3] + "\b")
.... time.sleep(0.1)
....
Point (2): Backspace??? YAGNI --- backspace hasn't been much use for
anything (except when typing text) since the days when in order to get
a bold letter (say X) on a character impact printer, one would
transmit X\bX\bX ...
 
D

Dustan

On 31 srp, 11:44, (e-mail address removed) wrote:

If you mean on operating system then unfortunately Windows XP.

Point (1) Works on Windows XP for me:

C:\junk>ver

Microsoft Windows XP [Version 5.1.2600]

C:\junk>\python25\python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Hellworld

or, for mild amusement:

... sys.stdout.write("|/-\\"[x & 3] + "\b")
... time.sleep(0.1)
...

Now try it on IDLE.
 
J

John Machin

On Jul 31, 8:01 pm, (e-mail address removed) wrote:
Point (1) Works on Windows XP for me:
C:\junk>ver

Microsoft Windows XP [Version 5.1.2600]
C:\junk>\python25\python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
text = "Hello\bworld"
print text Hellworld

or, for mild amusement:
import sys, time
for x in xrange(100):
... sys.stdout.write("|/-\\"[x & 3] + "\b")
... time.sleep(0.1)
...

Now try it on IDLE.

So the OP should have been slagging off at PythonWin and IDLE, not at
Windows.
 
H

Hendrik van Rooyen

John Machin said:
Point (2): Backspace??? YAGNI --- backspace hasn't been much use for
anything (except when typing text) since the days when in order to get
a bold letter (say X) on a character impact printer, one would
transmit X\bX\bX ...

ooooooh! Ugly!

Almost as bad as, on a golf ball printer:

"I am a little nodding man, I always nod my head..."

followed by an infinite loop of shift-in, shift-out characters.

- Hendrik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top