且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#.net中的字符串问题

更新时间:2023-02-17 08:16:41

确定-如果您基于空格对它进行拆分,则可以轻松编写显示该代码并在每四个字符串中插入一个换行符的代码.
OK - if you split it based on a space, you can easily write code that displays it and inserts a line break every fourth string.



您在"3 2 30 20"之前错过了一个"0".我加了.现在的结果是完美的..
试试这个:
Hi,
You missed one "0" before "3 2 30 20". I added that. Now the result is perfect..
Try this:
private void GetFormat()
{
    string str = "2 3 40 300 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 30 200 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 30 200";
    string[] s4 = str.Split(' ');
    int count = 0;
    foreach (string s2 in s4)
    {
        if (count < 4)
        {
            Console.Write(s2 + "\t");
            count++;
        }
        else
        {
            Console.WriteLine("");
            count = 0;
        }
    }
}



让我知道它是否对您有用.
--Amit



Let me know if it works for you.
--Amit



int i=0;
 foreach( var Parts in str.Split(' '))
  {
    Console.Out.writeLine(Parts+" ");
    i++;
    if(i==4)
    {
    Console.Out.WriteLine("");
    i=0;
    }
  }