simple string backspace question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vedrandekovic@v-programs.com

    simple string backspace question

    Hello,

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

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





    Regards,
    Vedran

  • Lawrence Oluyede

    #2
    Re: simple string backspace question

    <vedrandekovic@ v-programs.comwro te:
    >text="Hello\bw orld"
    >print text
    "HelloBSwor ld"
    >
    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\b world"
    >>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

    Comment

    • vedrandekovic@v-programs.com

      #3
      Re: simple string backspace question

      On 31 srp, 11:44, [email protected] wrote:
      Hello,
      >
      I have one simple string, backspace character question.Here is my
      example:
      >
      >text="Hello\bw orld"
      >print text
      >
      "HelloBSwor ld"
      >
      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

      Comment

      • Lawrence Oluyede

        #4
        Re: simple string backspace question

        <vedrandekovic@ v-programs.comwro te:
        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

        Comment

        • vedrandekovic@v-programs.com

          #5
          Re: simple string backspace question

          On 31 srp, 12:03, [email protected] (Lawrence Oluyede) wrote:
          <vedrandeko...@ v-programs.comwro te:
          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 "programmin g language", for code
          indentation. I don't know how to write script with module tokenize
          for code indentation.

          Regards,
          Vedran

          Comment

          • Diez B. Roggisch

            #6
            Re: simple string backspace question

            [email protected] wrote:
            On 31 srp, 12:03, [email protected] (Lawrence Oluyede) wrote:
            ><vedrandeko... @v-programs.comwro te:
            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
            >understandin g it" - Upton Sinclair
            >
            Hi,
            >
            I need this inevitable for my "programmin g 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">fo o</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

            Comment

            • John Machin

              #7
              Re: simple string backspace question

              On Jul 31, 10:33 pm, Dustan <DustanGro...@g mail.comwrote:
              On Jul 31, 7:17 am, John Machin <sjmac...@lexic on.netwrote:
              >
              >
              >
              On Jul 31, 8:01 pm, [email protected] wrote:
              >
              On 31 srp, 11:44, [email protected] wrote:
              >
              Hello,
              >
              I have one simple string, backspace character question.Here is my
              example:
              >
              >>text="Hello\b world"
              >>print text
              >
              "HelloBSwor ld"
              >
              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>\python 25\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\bwor ld"
              >>print text
              Hellworld
              >
              or, for mild amusement:
              >
              >>import sys, time
              >>for x in xrange(100):
              >
              ... sys.stdout.writ e("|/-\\"[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.


              Comment

              Working...