Add separator to string at every N characters?

后端 未结 13 2279
半阙折子戏
半阙折子戏 2020-11-27 13:20

I have a string which contains binary digits. How to separate string after each 8 digit?

Suppose the string is:

string x = \"111111110000000011111111         


        
13条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 13:40

    I am more than late with my answer but you can use this one:

        static string PutLineBreak(string str, int split)
        {
            for (int a = 1; a <= str.Length; a++)
            {
                if (a % split == 0)
                    str = str.Insert(a, "\n");
            }
    
            return str;
        }
    

提交回复
热议问题