我的数据库中有 2 个表。第一个是 Material 详细信息,第二个是类别 在 Material 详细信息中,我有 6 列(品牌、系列、电容、公差、 Material 外出) 在第二个我有(类别ID,category_Name) 我想从文本框中的用户处获取值,并从该值中生成一个子字符串。我该怎么做? C Sharp 代码
这会让你更好地理解...... “我正在开发一个演示网站。在我的网页上,我有 5 个标签和 5 个文本框。1.category 2.make 3.series 4.capacity,最后一个文本框是 Sub string。现在我希望每当用户填写 1 到 4 个文本框。应根据这些文本框的值生成子字符串。例如,如果用户输入类别为“school”,则将“samsung”系列设为“1234”,则该子字符串将生成类似于“SCH-SAM-123”..所有字段中的前三个单词。“”
最佳答案
//these codes will help you retrieve the values of each Text box to strings
TextBox objTextBox1 = (TextBox)input1;
string theText1 = objTextBox.Text;
同样为每个文本框生成 4 个字符串。 文本1 文本2 文本3 文本4
//This will extract first three characters from a string
string sub1 = theText1.Substring(0, 3);
类似地从上面创建的所有字符串中提取字符。
如果您希望字符为大写,请使用“string.ToUpper()”方法
提取所有字符串后,连接所有字符串
string results = sub1 + "-" + sub2 + "-" + sub3 "-" + sub4;
//Check the result
Console.WriteLine(results);
我希望本指南能够帮助您获得预期的结果。
谢谢
关于c# - 如何从多个文本框中插入的值生成子字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25458718/