关于C#字符串占位符的有关问题
关于C#字符串占位符的问题
将一个数据库查询语句嵌入到C#代码中,需要用到字符串的占位符,在C++中一般为:
在C++中
在C#中该如何运用占位符呢?
------解决方案--------------------
http://msdn.microsoft.com/zh-cn/library/system.string.format.aspx
------解决方案--------------------
{0},{1}形式
------解决方案--------------------
sql = string.Format("select * from GM7系列交流伺服变频主轴电机技术数据表 where 型号='{0}'"), str1);
将一个数据库查询语句嵌入到C#代码中,需要用到字符串的占位符,在C++中一般为:
在C++中
sql.Format(_T("select * from GM7系列交流伺服变频主轴电机技术数据表 where 型号='%s'"),str1);
在C#中该如何运用占位符呢?
------解决方案--------------------
string output = String.Format("At {0} in {1}, the temperature was {2} degrees.",
dat, city, temp);
http://msdn.microsoft.com/zh-cn/library/system.string.format.aspx
------解决方案--------------------
{0},{1}形式
------解决方案--------------------
sql = string.Format("select * from GM7系列交流伺服变频主轴电机技术数据表 where 型号='{0}'"), str1);