如何忽略“"中存在的定界符在vb.net中使用分割功能时 [英] How to ignore the delimiter present in "" while using split function in vb.net

查看:67
本文介绍了如何忽略“"中存在的定界符在vb.net中使用分割功能时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用.Split(,")在出现,"的地方拆分行,问题是字符串具有,"(例如:"Colarado,usa").因此,如何克服出现在"之间的,".

Trying to split a line wherever "," appears using .Split(","), The problem is string have "," (ex: "Colarado,usa"). So how to overcome the "," that appeared in between the "".

推荐答案

您不能.拆分没有任何选项来确定字符串中的平衡字段.

您将必须使用正则表达式将字符串与可选的分隔字段分开.我强烈建议选择 Expresso [ ^ ]来构建和测试您的正则表达式模式字符串.
You can''t. Split doesn''t have any options to determine quoated fields in a string.

You''ll have to use a Regular Expression to split the string with optional quoated fields. I highly suggest picking up Expresso[^] to build and test your regex pattern strings.


我为您提供解决方案!

它用大量的时间来解决类似的问题,仅用于按空格分隔,但您可以将我的解决方案用于您的案例.

我创建了此代码,以.NET模拟命令将空格预解析为字符串数组.它还考虑了引号,从而可以避免内部引号分裂.我需要它来加快对命令行实用程序的测试,而无需使用命令行本身(它帮助我真正快速地修复了许多错误).

现在,让我帮助您找到我的源代码.加载我的文章:基于枚举的命令行实用程序 [SA.Universal.Utilities.CommandLineSimulationUtility.

加载文章附带的源代码,然后在演示/测试应用程序中找到此实用程序.这是您需要的代码.

如果此代码有任何问题,请报告给我.

—SA
I have a solution for you!

It tool me considerable amount of time to solve the similar problem, only for splitting by blank space, but you can use my solution for your case.

I created this code to .NET simulate command pre-parsing into array of strings by blank space. It also takes into account quotation marks, to make it possible to avoid splitting inside quotation. I needed it to accelerate testing of my command line utility without using command line itself (and it helped me to fix number of bugs really fast).

Now, let me help you to locate my source code. Load my article: Enumeration-based Command Line Utility[^], see the section "6. CommandLine Testing". It explains SA.Universal.Utilities.CommandLineSimulationUtility.

Load the source code which comes to article and locate this utility in the demo/test application. This is the code you need.

Please report back to me if there is any problem with this code.

—SA


不是在字符上拆分,而是在."上拆分.
只需遍历整个数组,即可获取第二个字符(for 循环中的第2步).

获得第二个字符串后,从中删除.字符.
Instead of splitting on the , character, split on ".
Simply loop through the array such that you take every second character (step 2 in the for loop).

Once you have the second string, remove the , character from it.


这篇关于如何忽略“"中存在的定界符在vb.net中使用分割功能时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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