关于C#字符串占位符的问题

HUSTYZHY 2014-09-03 09:16:39
将一个数据库查询语句嵌入到C#代码中,需要用到字符串的占位符,在C++中一般为:
在C++中
sql.Format(_T("select * from GM7系列交流伺服变频主轴电机技术数据表 where 型号='%s'"),str1);

在C#中该如何运用占位符呢?
...全文
484 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
threenewbee 2014-09-03
  • 打赏
  • 举报
回复
sql = string.Format("select * from GM7系列交流伺服变频主轴电机技术数据表 where 型号='{0}'"), str1);
bdmh 2014-09-03
  • 打赏
  • 举报
回复
{0},{1}形式
全栈极简 2014-09-03
  • 打赏
  • 举报
回复
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

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧