By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,898 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,898 IT Pros & Developers. It's quick & easy.

simple string backspace question

P: n/a
Hello,

I have one simple string, backspace character question.Here is my
example:
>>text="Hello\bworld"
print text
"HelloBSworld"

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

Regards,
Vedran

Jul 31 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
<ve***********@v-programs.comwrote:
>text="Hello\bworld"
print text
"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.
>>text="Hello\bworld"
print text
Hellworld

What system are u using?

--
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
Jul 31 '07 #2

P: n/a
On 31 srp, 11:44, vedrandeko...@v-programs.com wrote:
Hello,

I have one simple string, backspace character question.Here is my
example:
>text="Hello\bworld"
print text

"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

Jul 31 '07 #3

P: n/a
<ve***********@v-programs.comwrote:
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 :-) ?

--
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
Jul 31 '07 #4

P: n/a
On 31 srp, 12:03, ra...@dot.com (Lawrence Oluyede) wrote:
<vedrandeko...@v-programs.comwrote:
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 :-) ?

--
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

Jul 31 '07 #5

P: n/a
ve***********@v-programs.com wrote:
On 31 srp, 12:03, ra...@dot.com (Lawrence Oluyede) wrote:
><vedrandeko...@v-programs.comwrote:
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 :-) ?

--
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.
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
Jul 31 '07 #6

P: n/a
On Jul 31, 10:33 pm, Dustan <DustanGro...@gmail.comwrote:
On Jul 31, 7:17 am, John Machin <sjmac...@lexicon.netwrote:
On Jul 31, 8:01 pm, vedrandeko...@v-programs.com wrote:
On 31 srp, 11:44, vedrandeko...@v-programs.com wrote:
Hello,
I have one simple string, backspace character question.Here is my
example:
>>text="Hello\bworld"
>>print text
"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.
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.
Jul 31 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.