Splitting a string into chunks of a certain size

后端 未结 30 2237
时光说笑
时光说笑 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:27

    Simple and short:

    // this means match a space or not a space (anything) up to 4 characters
    var lines = Regex.Matches(str, @"[\s\S]{0,4}").Cast().Select(x => x.Value);
    

提交回复
热议问题