首页 > 代码库 > [开发笔记]-分隔字符串

[开发笔记]-分隔字符串

一:javascript中实现分隔显示字符串

keyup(function () {                this.value = http://www.mamicode.com/this.value.replace(/[^\w{8}\d{8}]/g, "").replace(/(\w{4})(?=\w)/g, "$1 ");            });

效果:

 

二:C#中实现分隔字符串

  static void Main(string[] args)        {                        //int count = 13;            //int spt = 4;            //var xx = Math.Ceiling((double)count / spt);            //Console.Write(xx);            string str = "KEI4DXER345";            int spt = 4;            var xx = Math.Ceiling((double)str.Length/spt);            string result = string.Empty;            for (int i = 0; i < xx-1; i++)            {                result += str.Substring((i * 4), 4) + " ";            }            result += str.Substring(((int)(xx-1) * 4));            Console.Write("result:   [{0}]  ",result);

效果:

 

转载请注明出处。