3 c#
好吧,问题可能更好.我有一个字符串.
2008 apple micro pc computer
Run Code Online (Sandbox Code Playgroud)
我希望将' '前两个分隔符的字符串拆分,然后将其余部分保持在一起.所以它会回来
2008
apple
micro pc computer
Run Code Online (Sandbox Code Playgroud)
这是一个组成的字符串,所以它可以是任何东西,但它仍然是前两个分裂,然后所有其余的,不管其余的是多少
另一个例子
apple orange this is the rest of my string and its so long
Run Code Online (Sandbox Code Playgroud)
回报
apple
orange
this is the rest of my string and its so long
Run Code Online (Sandbox Code Playgroud)
Bol*_*ock 18
传递第二个参数以指定最多要分割的项目数.在你的情况下,你传递3,所以你有前两个部分按空格分割,其余的字符串在第三个.
string myString = "2008 apple micro pc computer";
string[] parts = myString.Split(new char[] { ' ' }, 3);
Run Code Online (Sandbox Code Playgroud)