我需要用分號(;
)作爲分隔符分隔字符串。括號內的分號應該被忽略。用分號和分隔符分隔字符串幷包含括號
實施例:
string inputString = "(Apple;Mango);(Tiger;Horse);Ant;Frog;";
串的輸出列表應該是:
(Apple;Mango)
(Tiger;Horse)
Ant
Frog
的其他有效輸入串可以是:
string inputString = "The fruits are (mango;apple), and they are good"
上述字符串應被劃分到單串
"The fruits are (mango;apple), and they are good"
string inputString = "The animals in (African (Lion;Elephant) and Asian(Panda; Tiger)) are endangered species; Some plants are endangered too."
上面的字符串應該被劃分到兩個字符串,如下圖所示:
"The animals in (African (Lion;Elephant) and Asian(Panda; Tiger)) are endangered species"
"Some plants are endangered too."
我搜索了很多,但找不到答案,上面的場景。
有沒有人知道如何在不重新發明輪子的情況下實現這個目標?
是。嘗試使用正則表達式 – Reniuz
感謝您的及時答覆。你能給個例子嗎? – user1571734
是否有理由使用分號作爲分隔符?你的結構非常接近[JSON](http://www.w3schools.com/json/default.asp),那爲什麼不使用它呢?沒有任何反對正則表達式,因爲這也會起作用,我只是一個標準支持者。 – iMortalitySX