Split string after certain character count

前端 未结 4 1268
刺人心
刺人心 2020-12-11 07:25

I need some help. I\'m writing an error log using text file with exception details. With that I want my stack trace details to be written like the below and not in straight

4条回答
  •  再見小時候
    2020-12-11 07:54

    Following example splits 10 characters per line, you can change as you like {N} where N can be any number.

    var input = "stacktraceabcdefghijklmnopqrstuvwxyztacktraceabcdefghijklmnopqrswxyztacktraceabcdefghijk";
    var regex = new Regex(@".{10}");
    string result = regex.Replace(input, "$&" + Environment.NewLine);
    Console.WriteLine(result);
    

    Here is the Demo

提交回复
热议问题