function getTLV(tag, content) {
var len = ""+content.replace(/[^\x00-\xff]|[\xa4\xa7\xa8\xb0\xb1\xb7\xd7\xe0\xe1\xe8\xe9\xea\xec\xed\xf2\xf3\xf7\xf9\xfa\xfc]/g, "**").length;
var size = len.length;
for(var i=0; i<10-size; i++) {
len = "0" + len;
}
var tlv = tag + len + content;
return(tlv);
}
谢谢各位大鸟,分数不多..

解决方案 »

  1.   

    参考:        string getTLV(string tag, string content)
            {
                string len = System.Text.RegularExpressions.Regex.Replace(content, @"[^\x00-\xff]|[\xa4\xa7\xa8\xb0\xb1\xb7\xd7\xe0\xe1\xe8\xe9\xea\xec\xed\xf2\xf3\xf7\xf9\xfa\xfc]", "**").Length.ToString();
                int size = len.Length;
                for (int i = 0; i < 10 - size; i++)
                {
                    len = "0" + len;
                }
                string tlv = tag + len + content;
                return tlv;
            }
      

  2.   

            private void getTLV(string tag, string content)
            {
                string len = "" + content.Replace("/[^\x00-\xff]|[\xa4\xa7\xa8\xb0\xb1\xb7\xd7\xe0\xe1\xe8\xe9\xea\xec\xed\xf2\xf3\xf7\xf9\xfa\xfc]/g", "**").Length;//js的这句不是很懂,难道不是字符串
                int size = len.Length;
                for (int i = 0; i < 10 - size; i++)
                {
                    len = "0" + len;
                }
                return tag + len + content;
            }