包括“ {”-在string.Format中签名

时间:2018-10-30 10:30:42

标签: c# .net string parsing formatting

我有一个想要插入其他字符串的字符串。为此,我使用了方法 let config = {/*the info*/} //connect to the data base const pool = new sql.ConnectionPool(config , function(err){ if(err) throw err; //get the keys and the values let colsName enter code here= Object.keys(theDataObj); let values = [] for(let i = 0; i < colsName.length; i++){ values.push(theDataObj[colsName[i]]); console.log(theDataObj[colsName[i]])//check to see what going in pool.request().query(`INSERT INTO ${tabelName}(${colsName}) VALUES (${values})` , function(err , result){ if(err) throw err; console.log(result) }); } }); ,但是由于我的string.Format()包含basestring符号,因此该方法不起作用。只要将它们从字符串中删除,代码就可以正常工作。

{

有人对为什么它不起作用有胶水吗?

1 个答案:

答案 0 :(得分:0)

您可以使用'$'轻松插入字符串。例如:

string inputString = "test";
string anotherString = "test2";
int? codeExample = null;
string example = $"here I am putting my value: {inputString} and I can do it over and over {anotherString} or with code blocks {codeExample ?? 0}";

//result: here I am putting my value: test and I can do it over and over test2 or with code blocks 0

参考:Microsoft Language Reference