截取字符串Substring

本文介绍了一种批量扫描条码并处理相关数据的方法,包括字符串操作、数据集管理和错误提示。通过截取和判断输入字符串,实现对条码范围的识别与验证,以及对特定格式(如“-”或“/”分隔)的处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

截取字符串(第一个字符串,最后一个,某个位置字符串)
string strGroupBatchCodeSub = strGroupBatchCode.Substring(0, strGroupBatchCode.IndexOf('_'));
判断是否含有某个字符串(“,”,“-”,“/”)
 if (strTextBoxValue.Contains(strTextBoxSub1))
#region yehy 批量扫条码
                        DataSet dsAllWorkJob = null;
                        if (textBox1.Text.Trim().ToString() != "")
                        {
                            DataSet dsAll = m_PlanOverAndBackLogic.GetInformation(strCurrentWorkType, strCraftplanNo, strDeptAll);
                            if (dsAll.Tables[0].Rows.Count > 0)
                            {
                                string strGroupBatchCode = "";
                                foreach (DataRow dst in dsAll.Tables[0].Rows)
                                {
                                    strGroupBatchCode = dst["Groupbatchcode"].ToString().Trim();
                                }
                                //组批次
                                string strGroupBatchCodeSub = strGroupBatchCode.Substring(0, strGroupBatchCode.IndexOf('_'));
                                //过程卡序号值
                                string strTextBoxValue = textBox1.Text.Trim().ToString();
                                //判断第一位和最后一位
                                //截取是否是 - /
                                string strTextBoxSub1 = "-";
                                string strTextBoxSub2 = "/";
                                //判断输入 是否含有 - 字符串
                                if (strTextBoxValue.Contains(strTextBoxSub1))
                                {
                                    string[] strTextBoxValueSub = strTextBoxValue.Split('-');
                                    string strGroupPin1 = "";
                                    string strGroupPin2 = "";
                                    int ij = 0;
                                    for (int i = 0; i < strTextBoxValueSub.Length; i++)
                                    {
                                        if (i ==0)
                                        {
                                            strGroupPin1 = strTextBoxValueSub[0];
                                        }
                                        else
                                        {
                                            strGroupPin2 = strTextBoxValueSub[1];
                                        }
                                        ij++;
                                    }
                                    //判断是否为两位
                                    if (ij == 2)
                                    {
                                        int intGroupPin1 = Convert.ToInt32(strGroupPin1);
                                        int intGroupPin2 = Convert.ToInt32(strGroupPin2);
                                        //判断第一个是否小于第二个
                                        if (intGroupPin1 < intGroupPin2)
                                        {
                                            string strGroupPinhe1 = strGroupBatchCodeSub + "_" + strGroupPin1;
                                            string strGroupPinhe2 = strGroupBatchCodeSub + "_" + strGroupPin2;
                                            dsAllWorkJob = m_PlanOverAndBackLogic.GetInformation1(strCurrentWorkType, strCraftplanNo, strDeptAll, strGroupPinhe1, strGroupPinhe2);
                                        }
                                        else
                                        {
                                            UserMessages.ShowInfoBox("输入格式如下(6-8)!");
                                        }

                                    }
                                    else
                                    {
                                        UserMessages.ShowInfoBox("输入格式如下(6-8)!");
                                    }
                                    
                                }
                                //判断输入 是否含有 / 字符串
                                else if (strTextBoxValue.Contains(strTextBoxSub2))
                                {
                                    string[] strTextBoxValueSub = strTextBoxValue.Split('/');
                                    string strTextBoxValueZhuH = "";
                                    for (int i = 0; i < strTextBoxValueSub.Length; i++)
                                    {
                                        strTextBoxValueZhuH += "'"+strGroupBatchCodeSub + "_" + strTextBoxValueSub[i] +"'"+ ",";
                                    }
                                    //将最后一个逗号去掉
                                    string strTextBoxValueZhuHZ = strTextBoxValueZhuH.Substring(0, strTextBoxValueZhuH.Length - 1);
                                    dsAllWorkJob = m_PlanOverAndBackLogic.GetInformation2(strCurrentWorkType, strCraftplanNo, strDeptAll, strTextBoxValueZhuHZ);
                                }
                                else
                                {
                                    UserMessages.ShowInfoBox("输入格式不正确!");
                                }
                            }
                            else
                            {
                                Timer("该条码下没有您的生产任务!");
                                this.KWTextBox.Text = "";
                                this.textBox1.Text = "";
                            }
                        }
                        #endregion
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值