码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-02 23:18:06      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   2014   

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

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

效果:

bubuko.com,布布扣

 

二: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);

效果:

bubuko.com,布布扣

 

转载请注明出处。

 

[开发笔记]-分隔字符串,布布扣,bubuko.com

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

标签:style   blog   http   java   color   2014   

原文地址:http://www.cnblogs.com/babycool/p/3818737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!