字符串分割问题

编程入门 行业动态 更新时间:2024-10-24 17:31:24
本文介绍了字符串分割问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在构建一个解析器,当涉及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, ",(?=(?:[^']*'[^']*')*[^']*

更多推荐

字符串分割问题

本文发布于:2023-11-29 00:31:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1644575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!