分割字符串并仅获取Second值 [英] Split string and get Second value only

查看:74
本文介绍了分割字符串并仅获取Second值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用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月7日至16日,而不是其余部分?

I just want the Second part, the 12-JUL-16 of string and not the rest?

推荐答案

是:

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

OR:

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();

这篇关于分割字符串并仅获取Second值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆