on the server side, either you count it yourself, or use System.Text.Encoding.GetEncoding("GB2312")'s GetByteCount method, for example:
string s = "abc中d013";
int nChCount = 0, nNonChCount = 0;
for (int i=0; i < s.Length; i++)
{
int n = (int) s[i];
if (n >= 0x4e00 && n <= 0x9fa5)
nChCount++;
else
nNonChCount++;
}
int nTotalCount = nChCount + (nNonChCount+1)/2;
Console.WriteLine(nTotalCount);
int nByteCount = System.Text.Encoding.GetEncoding("GB2312").GetByteCount(s);
Console.WriteLine(nByteCount);
nTotalCount = (nByteCount+1)/2;
Console.WriteLine(nTotalCount);
on the client side, you can do similarly
<script>
function CountChars(s)
{
var nChCount = 0;
var nNonChCount = 0;
for (var i=0; i < s.length; i++)
if (s.charCodeAt(i) >= 0x4e00 && s.charCodeAt(i) <= 0x9fa5)
nChCount++;
else
nNonChCount++;