C# 采用Spilt 每隔2个字符分割字符串


string str = "123456";
string[] arr =  str.MySplit(2);

 

static string[] MySplit(this string str, int count) {
      var list = new List<string>();
      int length = (int)Math.Ceiling((double)str.Length / count);
      
      for(int i = 0; i < length; i++) {
        int start = count * i;
        if(str.Length <= start) {
          break;
        }
        if(str.Length < start + count) {
          list.Add(str.Substring(start));
        } else {
          list.Add(str.Substring(start, count));
        }
      }
      
      return list.ToArray();
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM