Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add single quotes to string in c#?

I am adding mutliple values to single string , all the values should be like in this format '','' but I am getting "'',''" instead.

How can I remove these double qoutes? Here's the code I'm using:

string one = "\'"+ names[0, 0] +"\'"+","+"\'" + names[1, 0]+"\'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" +","+ "'" + splitted[3] + "'";
like image 962
user1619151 Avatar asked Oct 19 '25 02:10

user1619151


1 Answers

You don't have to escape single quote like "\'" instead you can simply use "'", so you code should be:

string one = "'" + names[0, 0] + "'" + "," + "'" + names[1, 0] + "'";
string[] splitted = one.Split('\'');
string ones = "'" + splitted[1] + "'" + "," + "'" + splitted[3] + "'";
like image 64
Habib Avatar answered Oct 21 '25 15:10

Habib