-4

So, I have a text string that I want to remove the "" from.

Here is my text string:

string= 'Sample this is a string text with "ut" '

Here is the output I want once using a regex expression:

string= 'Sample this is a string text with ut'

Here is my overall code:

import re
string= 'Sample this is a string text with "ut" '
re.sub('" "', '', string)

And the output just show the exact text in the string without any changes. Any suggestions?

James Davinport
  • 303
  • 7
  • 19

2 Answers2

6

You can simply use string.replace('"','')

F Blanchet
  • 1,430
  • 3
  • 21
  • 32
  • Is there any way once the string is replaced and removed, to write to as a csv file? – James Davinport May 28 '19 at 13:11
  • You can use the package [csv](https://docs.python.org/2/library/csv.html) to write it on a csv file. – F Blanchet May 28 '19 at 13:14
  • ## This removes al "" in a text file import re f = open("/home/dir1/ddl2", 'a+', encoding='latin-1') read_file=f.read() words= read_file.split() #string = words. [i.replace('"', '') for i in words ] – James Davinport May 28 '19 at 13:17
  • Thats my code to append the file that I removed the strings from but the output just shows [] and when i refresh the file and open it, the changes arn't made. – James Davinport May 28 '19 at 13:18
5

If you want just remove all " symbols, you can use str.replace instead:

string = string.replace('"', '')

vurmux
  • 9,420
  • 3
  • 25
  • 45