Replace each char in a multi-line string except space and \r \n, how?

Posted by Horace Ho on Stack Overflow See other posts from Stack Overflow or by Horace Ho
Published on 2010-04-28T03:48:46Z Indexed on 2010/04/28 3:53 UTC
Read the original article Hit count: 168

A multi-line string, e.g.

abc 123
456 def

wanted result (ordinal + 2):

cde 345
678 fgh

if I use:

text = "abc 123\n456 def"
add2=''.join(chr(ord(c)+2) for c in text)
print text
print add2

the space and \r \n will also be replaced, how can I add the exception of not including space, \r or \n in the 2nd line of code.

p.s. it's follow up to this question.

© Stack Overflow or respective owner

Related posts about python

Related posts about string-manipulation