Split string and get Second value only

前端 未结 5 776
闹比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:30

    Yes:

    var result = str.Split(',')[1];
    

    OR:

    var result = str.Split(',').Skip(1).FirstOrDefault();
    

    OR (Better performance - takes only first three portions of the split):

    var result = str.Split(new []{ ',' }, 3).Skip(1).FirstOrDefault();
    

提交回复
热议问题