本文共 856 字,大约阅读时间需要 2 分钟。
一:javascript中实现分隔显示字符串
keyup(function () { this.value = 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);
效果:
本文转自 酷小孩 博客园博客,原文链接:http://www.cnblogs.com/babycool/p/3818737.html ,如需转载请自行联系原作者