我需要用分号(;
)作为分隔符分隔字符串。括号内的分号应该被忽略。用分号和分隔符分隔字符串并包含括号
实施例:
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