C# How to split string based on 2 parameters?

后端 未结 2 755
借酒劲吻你
借酒劲吻你 2021-01-29 07:49

I have three string called This_is string1 and This is string2 There_is string3

How to split these 3 strings after \"This_\", \"T

2条回答
  •  星月不相逢
    2021-01-29 08:30

    The answer is simple, you can use the String.Split method, specifying the multiple delimiters (in your case the underscore and whitespace):

    str.Split(new char[]{'_',' '})
    

    LinQPad result:

    enter image description here

    If you want to split only the first part, you can use the 2nd overload of String.Split:

    str.Split(new char[]{'_',' '}, 2);
    

    and this is the result in LinQPad:

    enter image description here

提交回复
热议问题