2017-09-05 87 views
0

我怎么能把条件放在这里。就像如果我输入一个4位数的字符,它会把一个前缀是“F-”。C#字符计数条件

try 
{ 
    Service1 ws = new Service1(); 
    if (e.KeyChar == (char)13 && button1.Enabled == true) 
    { 
     inputtxt = F.Text.ToString(); 
     showpic(inputtxt); 
     if (ws.VerifyEID(inputtxt) == false) 
     { 
      MessageBox.Show("You have entered an incorrect Employee ID. Please try again!", "Attendance Monitoring System", MessageBoxButtons.OK, MessageBoxIcon.Warning); 
      F.Text = null; 
     } 



     else 
     { 
      panel1.Visible = false; 
      SqlToText(inputtxt); 
      ShowOffset(inputtxt); 
      if (BtnTimeIn.Visible == true) 
      { 
       BtnTimeIn.Focus(); 
      } 
      else 
      { 
       BtnTimeOut.Focus(); 
      } 
     } 

    } 

请帮助我,谢谢。

+0

您的代码似乎并不完整,并且不会编译为当前状态。 – juharr

+0

好的,所以你想在字符串前添加“f”,并且我假设你想要它在你有不完整的行的地方'if if(inputtext ='? – Ben

+0

My bad,Disregard that。I was editing the code while im在这里张贴,所以我不小心将它包括在内,呃,先生可以帮我 – Chddz

回答

0

你可以在你的代码中插入这样的:

inputtxt = inputtxt.StartsWith("F-") ? inputtxt : "F-" + inputtxt; 

但我会亲自对文本前缀,以明确对什么类型和让他们键入字符以内的用户。