由于一个老板的需要.在一个textBox中是这样输入的 45KG/包 当然也有可能会是这样的 3米/根 .当然还会出现很多其他的.反正就是单位长度或者单位重量.这个textBox中有3个值.怎么分别一一取出,让数据表中3个字段中.请大家很给力的告诉我好吗?最好能给出代码.
解决方案 »
- 【大家看下图】dataGridView【winform】
- 如何让在gridview中的单元格中按下回车健后,光标往后移,而不是往下移
- 如何定时,实时多线程发送邮件了,求好的解决方法
- 新生作业- - 各位大仙帮忙!
- 怎么实现从sql server数据库将数据导出到excel表中
- 在DataGrid(Windows)中,我选中一行,我通过什么方法才能行到这一行的数据并显示出来!
- ListBox请教,谢谢
- 自定义字段的一个问题
- 求一正则
- 高分求救 大侠们c#到底可不可以调用vc编写的动态连接库,那还要vc编写的组件干什末
- 关于linkbutton的click事件无法响应的问题
- 书上的程序,为什么会提示错误
string str = "45KG/包";
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(str, @"^(\d+)([^/]+)/(.+)$");
if (match.Success)
{
string[] result = new string[3];
for (int i = 0; i < result.Length; i++)
{
result[i] = match.Groups[i + 1].Value;
Console.WriteLine(result[i]);
}
}
string str = "∮3.2mm/粒";
System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(str, @"(?<num>\d+(\.\d+)*)(?<unit1>[^/]+)/(?<unit2>.+)");
if (match.Success)
{
string[] result = new string[3];
result[0] = match.Groups["num"].Value;
result[1] = match.Groups["unit1"].Value;
result[2] = match.Groups["unit2"].Value;
}
当遍历数组arr时,遇到'/'时跳出,得到 string s1="45kg" ,s2="/",s3="包"。
这样应该差不多了。