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
  • 21,991
  • 13
  • 83
  • 101
s.k.paul
  • 6,663
  • 24
  • 88
  • 159

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,624
  • 6
  • 35
  • 38
0

This is simply doing it

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