Reputation: 65
I am trying to clean text strings containing any '
or '
(which includes an ;
but if i add it here you will see just '
again. Because the the ANSI is also encoded by stackoverflow. The string content contains '
and when it does there is an error.
when i insert the string to my database i get this error:
psycopg2.ProgrammingError: syntax error at or near "s" LINE 1: ...tment and has commenced a search for mr. whitnell's
the original string looks like this:
...a search for mr. whitnell's...
To remove the '
and ' ;
I use:
stripped_content = stringcontent.replace("'","")
stripped_content = stringcontent.replace("' ;","")
any advice is welcome, best regards
Upvotes: 0
Views: 569
Reputation: 419
When you try to replace("' ;","")
it literally searching for "' ;"
occurrences in string. You need to convert "' ;"
to its character equivalent. Try this:
s = "That's how we 'roll"
r = s.replace(chr(int('''[2:])), "")
and with this chr(int('''[2:]))
you'll get '
character.
Output:
Thats how we roll
Note
If you try to run this s.replace(chr(int('''[2:])), "")
without saving your result in variable then your original string
would not be affected.
Upvotes: 1