本文介绍了内将字符串分割“,”入阵除外“,”()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有串像

"11,Standard(db=S,api=Standard),UI,1(db=1,api=STANDARD),Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36,1010,9999,1000,9998.0,,1"

我想焦炭分裂它,但我不喜欢有','内在()。请帮助如何分割在C#这样的字符串。
中忽略字符','()

I would like to split it by char ',' but i don't like to include ',' within the '()'. Please help how to split such string in c#.Ignore char ',' within ().

输出应该是这样的:

   array of string = [
     "11",
     "Standard(db=S,api=Standard)",
     "UI",
     "1(db=1,api=STANDARD)",
     "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36",
     "1010"

等。

推荐答案

如果该模式是始终,您可以使用一个正则表达式,以分裂的分隔符(逗号),比相匹配的令牌。确定是分隔符逗号需要一个相对简单的:(?=

If the pattern is always that you can use a RegularExpression in order to split on the delimiters (commas) than to match the tokens. Identifying the commas that are delimiters takes a relatively simple:

",(?=[^\)]*(?:\(|$))"

演示:的

说明:的

这篇关于内将字符串分割“,”入阵除外“,”()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:01
查看更多