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