使用 ASP.Net 和 C#,如何用一个字符串替换多个字符串?
在我的代码中,我使用这个循环来获取结果,但最后一个参数是唯一填充的参数。
public void smssend(string CustomerName,string from,string to,string date,string time)
{
con.Open();
string str1 = "select * from Master ";
SqlCommand command1 = new SqlCommand(str1, con);
SqlDataReader reader1 = command1.ExecuteReader();
while (reader1.Read())
{
Label1.Text = reader1["Template"].ToString();
}
reader1.Close();
string desc = Label1.Text;
string[] BadCharacters = { "1", "2", "3", "4","5" };
string[] GoodCharacters = { CustomerName, from, to, date,time };
string strReplaced = "";
int i;
for(i=0; i<=4; i++)
{
strReplaced = desc.Replace(BadCharacters[i], GoodCharacters[i]);
}
Label1.Text = strReplaced;
输出:
1 and 2 and 3 and 4 and 12:00:00
如何正确连接多个字符串?