String.Split only on first separator in C#?

后端 未结 4 1375
暖寄归人
暖寄归人 2020-12-08 05:59

String.Split is convenient for splitting a string with in multiple part on a delimiter.

How should I go on splitting a string only on the first delimiter. E.g. I\'ve

4条回答
  •  借酒劲吻你
    2020-12-08 06:25

    I've adopted a variation to Thorarin's answer above, The below should be able to handle your requirement, plus trim the spaces.

    yourString.Split(new []{'-'},2).Select(s => s.Trim())
    

提交回复
热议问题