数据库一个字段a,varchar,40个字节,
我更新这个字段,我可以输入20个汉字(全是),(一个汉字占2个字节),也可以输入40个数字(全是数字),也可以输入40个数字和字母组合。如何计算汉字和数字字母组合的的字节((((字节)))。。
我想控件输入的文本框的MaxLength,我应输入多少如果我设为20,输入20个字符,汉字可以占40个字节,数字只占20个字节

解决方案 »

  1.   

    string s="abc村械地23423";
    int byteCount=System.Text.Encoding.Default.GetByteCount(s);byteCount得到字符串变量里面的字符串所占字节数。
      

  2.   

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
    Dim intByte As Integer
    Dim strYourString As String strYourString = "全角aa全v角dd全角"
    intByte = System.Text.Encoding.Default.GetByteCount(strYourString)
    MessageBox.Show(CType(intByte, String))End Sub
      

  3.   

    文本框,maxlenth=40
    是汉字我只输入20个汉字,
    是数字我输入40个数字
      

  4.   

    回复人: blackhero(黑侠客) ( ) 信誉:100  2005-1-10 16:14:43  得分: 0  
     
    文本框,maxlenth=40
    是汉字我只输入20个汉字,
    是数字我输入40个数字----------------------------------------------------------------------没错,是这样的,你要实现什么???