Tom
Tom

Reputation: 22841

Replacing Microsoft Word Newline Character in Python

This feels like it should be an easy one, but I'm having trouble cleaning out the newline character in content pasted from Microsoft Word. Not a full line-break, but the CTRL ENTER character that shows up as a return arrow in Word. I've tried chr(10), chr(13), \u000D, \u000A and a few others, but I can't match it in a string.replace(). Should I be looking for a different character or do I need to use something other than the string.replace method?

Upvotes: 0

Views: 1669

Answers (2)

Chris Lawlor
Chris Lawlor

Reputation: 48902

you can get the ASCII value of the character like this:

for c in 'string':
    print ord(c), hex(ord(c))

once you know the code, it should be easy to kill the offender.

Upvotes: 2

nosklo
nosklo

Reputation: 222862

Run this:

print repr(mystringobject)

That will give a hint of which character you want to remove.

If still no clue, paste the result of the command above in the question, and I'll edit my answer.

Upvotes: 4

Related Questions