Splitting a string into chunks of a certain size

后端 未结 30 2071
时光说笑
时光说笑 2020-11-22 07:55

Suppose I had a string:

string str = \"1111222233334444\"; 

How can I break this string into chunks of some size?

e.g., breaking t

30条回答
  •  天涯浪人
    2020-11-22 08:26

        public static List SplitByMaxLength(this string str)
        {
            List splitString = new List();
    
            for (int index = 0; index < str.Length; index += MaxLength)
            {
                splitString.Add(str.Substring(index, Math.Min(MaxLength, str.Length - index)));
            }
    
            return splitString;
        }
    

提交回复
热议问题