拆分字符串并仅获取第二个值 [英] Split string and get Second value only
本文介绍了拆分字符串并仅获取第二个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以使用 split 将一个字符串分成几个部分,这些部分用逗号分隔,如下所示:
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
我只想要第二部分,字符串的 12-JUL-16 而不是其余部分?
I just want the Second part, the 12-JUL-16 of string and not the rest?
推荐答案
是:
var result = str.Split(',')[1];
或:
var result = str.Split(',').Skip(1).FirstOrDefault();
OR(更好的性能 - 只需要拆分的前三个部分):
OR (Better performance - takes only first three portions of the split):
var result = str.Split(new []{ ',' }, 3).Skip(1).FirstOrDefault();
这篇关于拆分字符串并仅获取第二个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文