0

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 ?

Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
s.k.paul
  • 7,099
  • 28
  • 93
  • 168

2 Answers2

3

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.

user2771704
  • 5,994
  • 6
  • 37
  • 38
0

This is simply doing it

String key= "BookName";
String value = "BookValue";
String result = String.Format(@"'{0}:' ""+{1}+""", key, value);