string methods (warning, newbie)

A

anthonyberet

Is there a string mething to return only the alpha characters of a string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'

If not then how best to approach this?
I have some complicated plan to cut the string into individual
characters and then concatenate a new string with the ones that return
true with the .isalpha string method.

Is there an easier way?
 
A

anthonyberet

anthonyberet said:
Is there a string mething [method] to return only the alpha characters of a string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'
erm, no it wouldn't, it would be 'TheBeatleshelpTickettoride', but you
get me, I am sure.
 
P

Peter Hansen

anthonyberet said:
Is there a string mething to return only the alpha characters of a string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'

If not then how best to approach this?
I have some complicated plan to cut the string into individual
characters and then concatenate a new string with the ones that return
true with the .isalpha string method.

Is there an easier way?

Look into the string module's "translate" function. It will
do this for you fairly easily.

-Peter
 
T

Terry Reedy

anthonyberet said:
Is there a string mething to return only the alpha characters of a
string?
eg 'The Beatles - help - 03 - Ticket to ride', would be
'TheBeatlesTickettoride'

I believe you can do this with string.translate (string module, not str())

tjr
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top