Splitting a string in C#

后端 未结 4 1921
北恋
北恋 2020-12-06 17:40

I am trying to split a string in C# the following way:

Incoming string is in the form

string str = \"[message details in here][another message here]/         


        
4条回答
  •  有刺的猬
    2020-12-06 18:01

    Instead of using a regex you could use the Split method on the string like so

    Split(new[] { '\n', '[', ']' }, StringSplitOptions.RemoveEmptyEntries)
    

    You'll loose [ and ] around your results with this method but it's not hard to add them back in as needed.

提交回复
热议问题