How to split a string, but also keep the delimiters?

前端 未结 23 2371
我在风中等你
我在风中等你 2020-11-21 06:32

I have a multiline string which is delimited by a set of different delimiters:

(Text1)(DelimiterA)(Text2)(DelimiterC)(Text3)(DelimiterB)(Text4)
23条回答
  •  执念已碎
    2020-11-21 06:53

    A very naive solution, that doesn't involve regex would be to perform a string replace on your delimiter along the lines of (assuming comma for delimiter):

    string.replace(FullString, "," , "~,~")
    

    Where you can replace tilda (~) with an appropriate unique delimiter.

    Then if you do a split on your new delimiter then i believe you will get the desired result.

提交回复
热议问题