字符串分割问题 [英] String Split Problem

查看:80
本文介绍了字符串分割问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个解析器,当涉及string.split()时,我遇到了一个问题.

I''m building a parser and I have a problem when it comes to string.split().

Dim currentstring As String
currentstring = "'They are running, John','the dogs'" 
currentstring.split(",")



当我分割字符串时,也会在撇号之间分割逗号.有什么方法可以解决这个问题,所以它只会将那些撇号分开吗?



When I split the string it will split the commas in between the apostrophes too. Is there any way to get around that so it will only split the ones out side the apostrophes?

推荐答案

String.Split无法解决这个问题.您可能应该使用 Regex [
String.Split cannot cope with this. You should probably use the Regex class[^].


同意Carlo.检查此样本和根据您的需要进行修改.
C#正则表达式拆分-方括号内的所有内容 [ ^ ]
Agree with Carlo. Check this sample & modify it based on your need.
C# Regex Split - everything inside square brackets[^]


您是否尝试过:

Have you tried this :

string currentstring = "'They are running, John','the dogs'";
string[] result = Regex.Split(currentstring, ",(?=(?:[^']*'[^']*')*[^']*


这篇关于字符串分割问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆