C#将前两个拆分成字符串,然后将其余的放在一起
好吧,这个问题的措辞可能更好。我有一根绳子C#将前两个拆分成字符串,然后将其余的放在一起,c#,C#,好吧,这个问题的措辞可能更好。我有一根绳子 2008 apple micro pc computer 我希望前两个分隔符的字符串按'分割,然后将其余的保留在一起。所以它会回来的 2008 apple micro pc computer 这是一个组成的字符串,所以它可以是任何东西,但它仍然是前2个分裂,然后所有的休息,无论多少是所有的休息 另一个例子 apple orange this is the rest of my string and its so long 返回
2008 apple micro pc computer
我希望前两个分隔符的字符串按'
分割,然后将其余的保留在一起。所以它会回来的
2008
apple
micro pc computer
这是一个组成的字符串,所以它可以是任何东西,但它仍然是前2个分裂,然后所有的休息,无论多少是所有的休息
另一个例子
apple orange this is the rest of my string and its so long
返回
apple
orange
this is the rest of my string and its so long
传递第二个参数,以指定最大拆分为多少项。在你的例子中,你要通过3,这样你就有了前两部分的空间分割,其余的字符串在第三
string myString = "2008 apple micro pc computer";
string[] parts = myString.Split(new char[] { ' ' }, 3);
string.LastIIndexof
字符串拆分它。拆分并获取前两个
string s = "this is a test for something";
string[] string_array = s.Split(' ');
int length = string_array.Length;
string first = string_array[0];
string second = string_array[1];
string rest = "";
for (int i = 2; i < length; i++) rest = rest + string_array[i] + " ";
rest.TrimEnd();
string s=“这是对某事的测试”;
字符串[]字符串数组=s.Split(“”);
int length=string_array.length;
字符串优先=字符串_数组[0];
字符串秒=字符串_数组[1];
字符串rest=“”;
对于(inti=2;i