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
''''testing1'''',''''testing2'''',''''testing3'''',''''testing4'''',''''testing5'''',''''testing6''''


Results should be like this
"testing1","testing2","testing3","testing4","testing5","testing6"



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

The results became like this which is not what i want.
"testing1,testing2,testing3,testing4,testing5,testing6"
Posted
Updated 7-Jun-21 6:30am
v2

1 solution

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


[edit]
Here is the actual code I used:
C#
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:
./test
Input: ''''testing1'''',''''testing2'''',''''testing3'''',''''testing4'''',''''testing5'''',''''testing6''''
Output: "testing1","testing2","testing3","testing4","testing5","testing6"


[/edit]
 
Share this answer
 
v2
Comments
Nkhanedzeni 7-Jun-21 8:07am    
Thanks, why is it adding the backslash or will it work like this?
"\"testing1\",\"testing2\",\"testing3\",\"testing4\",\"testing5\",\"testing6\""
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    
5ed!
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