通过逗号vb.net拆分值

时间:2018-03-21 06:36:35

标签: vb.net

我有以下字符串,我在VB.net中使用逗号分割函数尝试下面的示例输出,但没有运气。

这是我试过的代码:

Sub Main()
   Dim testString as String="1,1,PATRONAGE 
       DISTRIBUTIONS,A00001PATR01,N/A,N/A,ZZ 
       1000001,1000001,7,N/A,7,S63,"$6,411.88 ","$6,411.88 ",$0.00 ,Customer 
       1,,82327 330TH 
       ST,,ELLENDALE,MN,560264012,Yes,Yes,1000001,2/15/2018,Batch 
       1,PAT 01,1.82E+11,75911603,"$24,761.32 ",$0.00 ,"$24,761.32 
       ",100%,N/A,"$3,845.08 ",$648.22 ,"$3,845.08 ",100%,N/A,"$3,062.66 
       ",$0.00 
       ,$0.00 ,0%,N/A,"$4,069.99 ",$0.00 ,$0.00 ,0%,N/A,"$4,718.86 ",$0.00 
       ,$0.00 
       ,0%,N/A,"$6,259.78 ",$0.00 ,$0.00 ,0%,N/A,"$5,933.43 ",$0.00 ,$0.00 
       ,0%,N/A,"$12,178.72 ",$0.00 ,$0.00 ,0%,N/A,"$13,980.26 ",$0.00 ,$0.00 
       ,0%,N/A,"$5,763.66 ","$5,763.66 
       ","$5,763.6",100%,N/A,N/A,N/A,N/A,N/A,Coming 
       Summer 2018,"$84,573.76 ","$6,411.88 ","$34,370.06 ",41%,N/A,"$34,370.06""

   Dim strElements() As String = Split(testString,",$")
   Console.WriteLine("1. " & strElements(0))
   For i As Integer = 1 To strElements.Count - 1
       Console.WriteLine((i + 1).ToString & ". $" & strElements(i))
   Next

   Console.ReadKey()
End Sub

输入:

1,1,PATRONAGE DISTRIBUTIONS,A00001PATR01,N/A,N/A,ZZ 
1000001,1000001,7,N/A,7,S63,"$6,411.88 ","$6,411.88 ",$0.00 ,Customer 
1,,82327 330TH ST,,ELLENDALE,MN,560264012,Yes,Yes,1000001,2/15/2018,Batch 
1,PAT 01,1.82E+11,75911603,"$24,761.32 ",$0.00 ,"$24,761.32 
",100%,N/A,"$3,845.08 ",$648.22 ,"$3,845.08 ",100%,N/A,"$3,062.66 ",$0.00 
,$0.00 ,0%,N/A,"$4,069.99 ",$0.00 ,$0.00 ,0%,N/A,"$4,718.86 ",$0.00 ,$0.00 
,0%,N/A,"$6,259.78 ",$0.00 ,$0.00 ,0%,N/A,"$5,933.43 ",$0.00 ,$0.00 
,0%,N/A,"$12,178.72 ",$0.00 ,$0.00 ,0%,N/A,"$13,980.26 ",$0.00 ,$0.00 
,0%,N/A,"$5,763.66 ","$5,763.66 ","$5,763.6",100%,N/A,N/A,N/A,N/A,N/A,Coming 
 Summer 2018,"$84,573.76 ","$6,411.88 ","$34,370.06 ",41%,N/A,"$34,370.06"

输出:

1
1
PATRONAGE DISTRIBUTIONS
N/A
N/A
$10,250
$10,000
$1200
etc 

如何构建上述输出?是否有任何正则表达式来分割值并构建上面的输出?

1 个答案:

答案 0 :(得分:0)

更改您的输入:

  

1,1,PATRONAGE DISTRIBUTIONS,A00001PATR01,N / A,N / A,ZZ   1000001,1000001,7,N / A,7,S63,“$ 6,411.88”,“$ 6,411.88”,$ 0.00,客户   1,,82327 330TH   ST ,, ELLENDALE,MN,560264012,是,是,1000001,2 / 15/2018,第1批,PAT   01,1.82E + 11,75911603,“$ 24,761.32”,$ 0.00,“$ 24,761.32   “,100%,N / A,”$ 3,845.08“,$ 648.22,”$ 3,845.08“,100%,N / A,”$ 3,062.66   “,$ 0.00,$ 0.00,0%,N / A,”$ 4,069.99“,$ 0.00,$ 0.00,0%,N / A,”$ 4,718.86   “,$ 0.00,$ 0.00,0%,N / A,”$ 6,259.78“,$ 0.00,$ 0.00,0%,N / A,”$ 5,933.43   “,$ 0.00,$ 0.00,0%,N / A,”$ 12,178.72“,$ 0.00,$ 0.00,0%,N / A,”$ 13,980.26   “,$ 0.00,$ 0.00,0%,N / A,”$ 5,763.66“,”$ 5,763.66   “,”$ 5,763.6“,100%,N / A,N / A,N / A,N / A,N / A,即将到来的夏季2018年,”84,573.76美元   “,”$ 6,411.88“,”$ 34,370.06“,41%,N / A,”$ 34,370.06“

到下面,(用PIPE符号替换所有分隔符并删除引号)

  

1 | 1 | PATRONAGE DISTRIBUTIONS | A00001PATR01 | N / A | N / A | ZZ   1000001 | 1000001 | 7 | N / A | 7 | S63 | $ 6,411.88 | $ 6,411.88 | $ 0.00 |客户   1 || 82327 330TH   ST || ELLENDALE | MN | 560264012 |是|是| 1000001 | 2/15/2018 |批次1 | PAT   01 | 1.82E + 11 | 75911603 | $ 24,761.32 | $ 0.00 | $ 24,761.32 | 100%| N / A | $ 3,845.08   | $ 648.22 | $ 3,845.08 | 100%| N / A | $ 3,062.66 | $ 0.00 | $ 0.00 | 0%| N / A | $ 4,069.99   | $ 0.00 | $ 0.00 | 0%| N / A | $ 4,718.86 | $ 0.00 | $ 0.00 | 0%| N / A | $ 6,259.78 | $ 0.00   | $ 0.00 | 0%| N / A | $ 5,933.43 | $ 0.00 | $ 0.00 | 0%| N / A | $ 12,178.72 | $ 0.00 | $ 0.00   | 0%| N / A | $ 13,980.26 | $ 0.00 | $ 0.00 | 0%| N / A | $ 5,763.66   | $ 5,763.66 | $ 5,763.6 | 100%| N / A | N / A | N / A | N / A | N / A |即将到来的夏天   2018 | $ 84,573.76 | $ 6,411.88 | $ 34,370.06 | 41%| N / A | $ 34,370.06 |

更改行:

Dim strElements()As String = Split(testString,“,$”)

到下面一行:

Dim strElements()As String = Split(testString,“|”)