Reputation: 7301
I want to create a string as shown in the text below :
'bookNo':'" + bookNo + "'
My code is
String KeyValuePair =
String.Format("'{0}':'\" + {1} + \"'", key,value);
But its not returning exact string as above. What can be done to achieve the same ?
Upvotes: 0
Views: 10286
Reputation: 9947
This is simply doing it
String key= "BookName";
String value = "BookValue";
String result = String.Format(@"'{0}:' ""+{1}+""", key, value);
Upvotes: 0
Reputation: 6212
I know two ways to do it: (I have already tested it)
1) using escape sequences \" and \'
string.Format("\'{0}\':\'\" + {1} + \"\'",key,value);
2) using verbatim string character @
string.Format(@"'{0}':'"" + {1} + ""'",key,value);
Hope it will help you.
Upvotes: 3