Perform Trim() while using Split()

后端 未结 7 1203
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-23 15:53

today I was wondering if there is a better solution perform the following code sample.

string keyword = \" abc, foo  ,     bar\";
string match = \"foo\";
str         


        
相关标签:
7条回答
  • 2020-12-23 16:58

    I know this is 10 years too late but you could have just split by ' ' as well:

    string[] split= keyword.Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
    

    Because you're also splitting by the space char AND instructing the split to remove the empty entries, you'll have what you need.

    0 讨论(0)
提交回复
热议问题