Click here to Skip to main content
15,566,390 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a string that adds extra quotes and I would like to remove those double quotes with single quotes. I have tried different scenarios and I haven't got any luck. I know it is a small issue that I might be missing something.

Thanks for your help in advance.

What I have tried:

Below is the string array

Results should be like this

I have tried to do this
string output = Regex.Replace(Usernames, "''''", "");

The results became like this which is not what i want.
Updated 7-Jun-21 6:30am

1 solution

Your replacement string is empty. Try:
string output = Regex.Replace(Usernames, "''''", "\"");

Here is the actual code I used:
string Usernames = "''''testing1'''',''''testing2'''',''''testing3'''',''''testing4'''',''''testing5'''',''''testing6''''";
Console.WriteLine("Input: {0}", Usernames);
string output = Regex.Replace(Usernames, "''''", "\"");
Console.WriteLine("Output: {0}", output);

And here is the resulting output:
Input: ''''testing1'''',''''testing2'''',''''testing3'''',''''testing4'''',''''testing5'''',''''testing6''''
Output: "testing1","testing2","testing3","testing4","testing5","testing6"

Share this answer
Nkhanedzeni 7-Jun-21 8:07am    
Thanks, why is it adding the backslash or will it work like this?
Richard MacCutchan 7-Jun-21 8:16am    
The code I gave you is not adding the backslash. See updated solution.
Maciej Los 8-Jun-21 9:13am    
The backslash is in this case an escape character.
Maciej Los 8-Jun-21 9:13am    
Richard MacCutchan 8-Jun-21 9:17am    
Thanks Maciej.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900