如何在多个空格上执行分割? [英] How to perform a Split on multiple spaces?

查看:104
本文介绍了如何在多个空格上执行分割?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Forms应用程序.我正在将CSV文件(从网站调查表中)导入DataGridView.

I have a Windows Forms application. I am importing CSV files (from a website questionnaire) into a DataGridView.

然后,我需要用相关信息填充DataGridView中的不同列.一些人错误地填写了调查表,我需要将答案分成正确的列.我会给你一个例子-

I then need to populate the different columns in the DataGridView with the relevant information. A few people have filled in the Questionnaire incorrectly and I need to split the answers into the correct columns. I will give you an example -

有些人在同一答案中填写了2个不同的电子邮件地址.它们之间用空格,等号和另一个空格分隔.一封电子邮件需要进入一个列,而另一封电子邮件则需要进入另一列.

Some people have filled 2 different e-mail addresses into the same answer. They are separated with a space, an equals sign and another space. One e-mail needs to go into one column and the other e-mail into another column.

我该如何拆分这些?我知道一次常规"拆分将处理一个空格"和一个字符,但是我不确定如何拆分一个前后都有空格的字符(等号).

How could I split these up? I know that a 'normal' split will deal with one 'space' and a character but I'm not sure how I need to split a character (equals sign) that has a space both before and after it.

有人可以给我一些想法吗?

Could someone give me a few ideas?

我感谢您的帮助.

推荐答案

        '在一个字段中的三封电子邮件
       Dim test As String ="foo@bar.com = bar@foo.com  foob​​ar@foobar.com"
       Dim s()作为字符串

       s = test.Split(New Char(){" c,="= c",StringSplitOptions.RemoveEmptyEntries)

        'three emails in one field
        Dim test As String = "foo@bar.com = bar@foo.com   foobar@foobar.com"
        Dim s() As String

        s = test.Split(New Char() {" "c, "="c}, StringSplitOptions.RemoveEmptyEntries)


这篇关于如何在多个空格上执行分割?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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