strings

Discussion in 'Python' started by Egor Bolonev, Jun 29, 2003.

  1. Egor Bolonev

    Egor Bolonev Guest

    Hi All!

    I have a
    'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    and I want a
    'Pink Floyd'
    How can I manage it?

    This one isn't work.
    author=f.read(30).replace('\0',' ').rstrip() #from mp3 tag


    --
    Egor [ru eo en]
     
    Egor Bolonev, Jun 29, 2003
    #1
    1. Advertising

  2. On Mon, 30 Jun 2003 09:54:24 +1100, "Egor Bolonev" <> wrote:

    >Hi All!
    >
    >I have a
    >'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    >and I want a
    >'Pink Floyd'
    >How can I manage it?
    >
    >This one isn't work.
    >author=f.read(30).replace('\0',' ').rstrip() #from mp3 tag
    >

    Trick question ;-)

    >>> pf = 'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    >>> pf[:pf.index('/x00')]

    'Pink Floyd'
    >>> list(pf)

    ['P', 'i', 'n', 'k', ' ', 'F', 'l', 'o', 'y', 'd', '/', 'x', '0', '0', '/', 'x', '0', '0', '/',
    'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '
    /', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0', '/', 'x', '0', '0
    ']

    I.e., '/x00' is not '\x00' ;-)

    Regards,
    Bengt Richter
     
    Bengt Richter, Jun 30, 2003
    #2
    1. Advertising

  3. On Mon, 30 Jun 2003 10:27:52 +1100, "Egor Bolonev" <> wrote:

    >> > Hi All!
    >> >
    >> > I have a
    >> > 'Pink Floyd/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00/x00'
    >> > and I want a
    >> > 'Pink Floyd'
    >> > How can I manage it?
    >> >
    >> > This one isn't work.
    >> > author=f.read(30).replace('\0',' ').rstrip() #from mp3 tag

    If you are playing around with various methods, don't forget
    to f.seek(0) between (assuming what you have is at the beginning of the file).

    >> >

    >>
    >> That is weird. Are you sure? It works on my system:
    >> (BTW: I think you mean \x00 instead of /x00)
    >>
    >> >>> a='Pink Floyd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    >> >>> a

    >> 'Pink Floyd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    >> >>> a.replace('\0',' ').rstrip()

    >> 'Pink Floyd'
    >> >>>

    >
    >Yes it's weird. The Interactive window of PythonWin shows it correct, but
    >debugger window is not.:-(

    Did you try it with a fixed string like a above?

    BTW, a.replace('\0','') should work without creating and then stripping spaces, I think.
    also a.rstrip('\0') -- though the meanings of all these are different if \x00 occurs internally,
    not just in the tail.

    Regards,
    Bengt Richter
     
    Bengt Richter, Jun 30, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kurt Krueckeberg
    Replies:
    2
    Views:
    718
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Nov 17, 2004
  2. Rick

    Comparing strings from within strings

    Rick, Oct 21, 2003, in forum: C Programming
    Replies:
    3
    Views:
    388
    Irrwahn Grausewitz
    Oct 21, 2003
  3. Klaus Neuner
    Replies:
    7
    Views:
    501
    Klaus Neuner
    Jul 26, 2004
  4. Girish Sahani
    Replies:
    17
    Views:
    575
    Boris Borcic
    Jun 9, 2006
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    772
    Malcolm
    Jun 24, 2006
Loading...

Share This Page