Asp.Net 判斷TEXTBox輸入字節長度

来源:互联网 发布:tensorflow有趣的项目 编辑:程序博客网 时间:2024/06/10 05:40
  public int CountByte(String strToByte, Encoding enc)        {             return enc.GetByteCount(strToByte);        }   protected void btnSave_Click(object sender, EventArgs e)        {            //以下為中文為2個字節,英文為一個字節
                if(CountByte(txtProjectName.Text,Encoding.UTF8)>50)                {                    RFQCommon.ShowMsg(this"Project Name can not over 50 Charater.");                    return;                }
                       //如編碼方式更改為Encoding.Unicode中文及英文均為2個字節
                if(CountByte(txtProjectName.Text,Encoding.Unicode)>50)                {                    RFQCommon.ShowMsg(this"Project Name can not over 50 Charater.");                    return;                }

               }
                                             
0 0
原创粉丝点击