如何从插入多个文本框中的值生成子字符串值

时间:2014-08-23 05:19:12

标签: c# mysql substring

我的数据库中有2个表。第1个是material_details,第2个是类别 在material_details我有6列(制造,系列,电容,公差,材料郊游) 在第二个我有(类别ID,category_Name) 我想从文本框中的用户获取值,并从该值想要生成子字符串。我可以这样做吗? c sharp中的代码

这将使你明白更好....... "我正在开发一个演示网站。在我的网页上我有5个标签和5个文本框。 1.category 2.make 3.series 4.capacity和最后一个文本框是Sub string。现在我希望用户填写1到4个文本框时。应该通过这些文本框的值生成子字符串..例如..如果用户输入类别为" school"作为"三星"系列为" 1234"将生成的子字符串类似于" SCH-SAM-123" ..来自所有字段的前三个字。""

1 个答案:

答案 0 :(得分:0)

//these codes will help you retrieve the values of each Text box to strings
TextBox objTextBox1 = (TextBox)input1;
string theText1 = objTextBox.Text;

同样为每个文本框生成4个字符串。 theText1 theText2 theText3 theText4

//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);

我希望本指南能帮助您获得预期的效果。

由于