C# 引号的小问题

来源:百度知道 编辑:UC知道 时间:2024/06/13 23:19:02
string userId,password;
string queryCmd;
queryCmd="adduser:userid=\""+textBox1.Text+"\",password=\""+textBox2.Text+"\";";
就是引号到底要怎么来用, 里面的adduser是dll类里面的一个接口里面的函数
[DllImport("samspiclient.dll")]
public static extern string fCommand(string cmd);

名看懂. 再说明白些.

如果在字符串中写引号需要转义(\")
queryCmd = "userid=\"" + userId + "\";";

补充:
在dll中用法也是一样的呀.

queryCmd = "adduser:userid=" + textBox1.Text + ",password=" + textBox2.Text + ";";

string类型的字符串要用""扩起来 \是用来获得特殊字符的 \" 就是得到纯"
"adduser:userid=\"" 显示出来就是 adduser:userid"
string可以用+来连接
你这段话可以简单为
string a = "adduser:userid=\"";
string b = textBox1.Text;
string c = "\",password=\"";
string d = textBox2.Text;
string e = "\";";
queryCmd = a + b + c + d + e;
结果就是 adduser:userid="box1",password="box2";

引号嘛 双引号引字符串挖
单引号--转义字符