Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > strings

Reply
Thread Tools

strings

 
 
Egor Bolonev
Guest
Posts: n/a
 
      06-29-2003
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]


 
Reply With Quote
 
 
 
 
Bengt Richter
Guest
Posts: n/a
 
      06-30-2003
On Mon, 30 Jun 2003 09:54:24 +1100, "Egor Bolonev" <(E-Mail Removed)> 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[f.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
 
Reply With Quote
 
 
 
 
Bengt Richter
Guest
Posts: n/a
 
      06-30-2003
On Mon, 30 Jun 2003 10:27:52 +1100, "Egor Bolonev" <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strings, Strings and Damned Strings Ben C Programming 14 06-24-2006 05:09 AM
How to generate k+1 length strings from a list of k length strings? Girish Sahani Python 17 06-09-2006 11:01 AM
Catching std::strings and c-style strings at once Kurt Krueckeberg C++ 2 11-17-2004 03:53 AM
convert list of strings to set of regexes; convert list of strings to trie Klaus Neuner Python 7 07-26-2004 07:25 AM
Comparing strings from within strings Rick C Programming 3 10-21-2003 09:10 AM



Advertisments