Split string and get Second value only

前端 未结 5 777
闹比i
闹比i 2021-01-01 02:05

I wonder if it\'s possible to use split to divide a string with several parts that are separated with a comma, like this:

10,12-JUL-16,11,0

5条回答
  •  清酒与你
    2021-01-01 02:29

    Use LINQ's Skip() and First() or FirstOrDefault() if you are not sure there is a second item:

    string s = "10,12-JUL-16,11,0";
    string second = s.Split(',').Skip(1).First();
    

    Or if you are absolutely sure there is a second item, you could use the array accessor:

    string second = s.Split(',')[1];
    

提交回复
热议问题