replace text that contains comma and quotes (1 Viewer)

anski

Registered User.
Local time
Tomorrow, 01:16
Joined
Sep 5, 2009
Messages
93
i want to replace the text: ,"dummy" with null.
this is my code: stemp = replace(stemp, ",""dummy""", "")
it does not work. what is the correct code to deal with both the comma and the double quote? tia.
 

MrHans

Registered User
Local time
Today, 19:16
Joined
Jul 27, 2015
Messages
147
You need to perform 2 seperate replacements.
First replace the comma with nothing, then replace the the quotes with nothing.

I would advice to use the Chr() function to do the replacement.

Replace(string,chr(ascii-nr),"")
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:16
Joined
May 7, 2009
Messages
19,242
Maybe you need some extra quote:


replace(stemp, ","""dummy"""", "")
 

anski

Registered User.
Local time
Tomorrow, 01:16
Joined
Sep 5, 2009
Messages
93
thanks for the quick response. i have commas and double quotes in the file that should not be replaced. i need to replace the comma and quotes that are in this format: comma-double quote-text-double quote with null.
 

MrHans

Registered User
Local time
Today, 19:16
Joined
Jul 27, 2015
Messages
147
You can do it in 1 replacement using the Chr() function.

Replace(string, chr(32) & chr(nr-for-quote), "") and then remove the last character with the mid function for example...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:16
Joined
May 7, 2009
Messages
19,242
Create an Update Query:

UPDATE Table1 SET Table1.stemp= Replace([stemp],",""dummy""","");
 

anski

Registered User.
Local time
Tomorrow, 01:16
Joined
Sep 5, 2009
Messages
93
Create an Update Query:
UPDATE Table1 SET Table1.stemp= Replace([stemp],",""dummy""","");
i am updating a csv file exported from a union query. i found a workaround for this.
1st replace: (sTemp, """DUMMY""", "DUMMY") --replace with just the word DUMMY with no quotes.
2nd replace: (sTemp, ",DUMMY", "")
 

isladogs

MVP / VIP
Local time
Today, 18:16
Joined
Jan 14, 2017
Messages
18,219
I don't understand the issue. This works for me:

SELECT Table3.ID, Table3.Field1, Replace([Field1],",""DUMMY""","") AS New
FROM Table3;



NOTE: I've deliberately included 2 records that don't work.
ID=1 fails as there is no comma; ID=4 fails as there is a space after the comma

Check that neither of these apply in your case
 

Attachments

  • Capture.PNG
    Capture.PNG
    6.9 KB · Views: 212

anski

Registered User.
Local time
Tomorrow, 01:16
Joined
Sep 5, 2009
Messages
93
^You are correct.
Replace([stemp],",""dummy""","") actually works. I used it again and it worked. There must have been a line in my code that did not make it work previously.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 01:16
Joined
May 7, 2009
Messages
19,242
See post #7.
 

Users who are viewing this thread

Top Bottom