根据变化的空格分割字符串

时间:2016-10-19 04:48:42

标签: c# asp.net vb.net

我正在阅读一个文本文件,我的测试文件中有以下几行

Item1             Item2       Item3   Item4                    Item5      Item6      Item7      Item8                   Item9                  Item10

12345678          TEST       0010  This is a Test              10/12/2016 23:07:24   1066891     TestName                 1232132 

23213213             Test1     0012    This is a Test            10/12/2016   23:07:24  1076578     Testname1                 32432432 

                               0076      This is Test2             10/14/2016   22:10:2  121342       TestName2                  23463246

23213213             Test1     0012    This is a Test            10/12/2016   23:07:24  1076578     Testname1                 32432432           TestQuality

我需要解析这些行并将它们放在数据库中。解析基于空格,所以

tabl1 A

第1项 - > Col1 Item2 - > Col2 Item3-> col3 Item4-> col4等等

我的问题是解析上述行的最佳方法是什么,因为项目之间的宽度/空格不同,有时Item1和Item2不存在,只有Item3存在,有时Item10不存在,有时Item1存在, item2不存在,然后其余项目存在。

如果其中一个项目不存在,那么我将不会在数据库中插入该特定项目并继续。我知道如何在数据库中插入项目,但我不知道解析具有不同空格的行的最佳方法。好处是物品之间总是有空格。它只是空间不一致。

任何帮助将不胜感激。

0 个答案:

没有答案