1. 程式人生 > >擷取字串Substring

擷取字串Substring

擷取字串(第一個字串,最後一個,某個位置字串)

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