StringTokenizer 中的连续分隔符
我必须标记以下字符串,
12/12/2010:{content1:[{xyz,abc}],13/12/2010:{content2:[{xyz,abc},{content3:[{aa,bb}]}]
如果它有 }] ,我需要将上面的字符串拆分。所以我这样做了,
String[] tokens = null;
StringTokenizer csvToken = new StringTokenizer(csvString,"]}");
tokens = new String[csvToken.countTokens()];
int tmp = 0;
while(csvToken.hasMoreTokens()) {
tokens[tmp++] = csvToken.nextToken();
}
但它并没有像我预期的那样标记化。
12/12/2010:{content1:[{xyz,abc
,13/12/2010:{content2:[{xyz,abc
,{content3:[{aa,bb
但我期望的是,
12/12/2010:{content1:[{xyz,abc
,13/12/2010:{content2:[{xyz,abc},{content3:[{aa,bb
我怎样才能使代码按预期工作?
I have to tokenize the following String
12/12/2010:{content1:[{xyz,abc}],13/12/2010:{content2:[{xyz,abc},{content3:[{aa,bb}]}]
I nee to split up the above string if it has }] consequtively. So I did,
String[] tokens = null;
StringTokenizer csvToken = new StringTokenizer(csvString,"]}");
tokens = new String[csvToken.countTokens()];
int tmp = 0;
while(csvToken.hasMoreTokens()) {
tokens[tmp++] = csvToken.nextToken();
}
But it is not tokenizing as I expected.
12/12/2010:{content1:[{xyz,abc
,13/12/2010:{content2:[{xyz,abc
,{content3:[{aa,bb
But What I expect was,
12/12/2010:{content1:[{xyz,abc
,13/12/2010:{content2:[{xyz,abc},{content3:[{aa,bb
how Could I make the code to work as expected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
String.split(String regex) 怎么样?
what about String.split(String regex)?
好吧,看到还没有答案,我的“快速修复”如下:
就个人而言,我将使用
String.split()
方法并使用我的解决方案“想法”,如上所述。或者,如果您足够勇敢,可以使用正则表达式。PS 代码经过测试并有效......
输出:
Ok, seeing that there's no answers yet, my "quick fix" are as follows:
Personally, I'll use
String.split()
method and use my solution "idea" as above. Or, if you're brave, use regular expressions.PS Code tested and worked....
Output: