我有一个看起来像这样的文本文件(但有数百行):
1147-1 SYRUP: DR.PEPPER 5GALLON/BOX
1653-1 SYRUP: DIET DR.PEPPER 5GAL/BOX
2011-2 WATER DISTILLED 6 / 1 GA
1217-2 ALL PURPOSE RASPBERRY FIL 40#
1273-1 STRAWBERRY PIE FILLING 38#
2893-1 BREAD: SOURDOUGH 12/1# OVAL
2287-1 BREAD SQUAW: 8/2.25#LF
1929-1 VINEGAR HERB CONT GRDN 12/12.7
1949-2 KETCHUP: 16/14OZ-PLASTIC BTLS
2408-1 CONE 3 NAB SAMPLER 28/45
2939-1 DULCE LECH FLVR PKT 3/12 EA CS
3017-1 GINGRBRD FLVR PKT 3/12 EA CS
3055-2 EGGNOG FLVR PKT 3/12 EA CS
3192-1 ORIGINAL MRS. DASH SEASONING
我已创建代码,逐行从文本文件中提取所有内容,并删除开头的数字并保存下一部分(即SYRUP: DR.PEPPER 5GALLON/BOX
,ALL PURPOSE RASPBERRY FIL 40#
) Mid(nextLine, 10, 30)
。我想通过提取名称(SYRUP: DR.PEPPER
,ALL PURPOSE RASPBERRY FIL
),大小(5GALLON
,40#
)来获取该部分并将其拆分(如果它是12/1#
= 12x 1LB
)和单位(BOX
,LB
)。正如您所看到的,几乎每条线都不同但有许多相似之处。不确定接下来该做什么。我一直在尝试使用:
re.Pattern = "GALLON|BOX|#|LF|GAL|EA|CS|BTLS"
取出单位部分,但我不知道还能做什么。
以下是我目前为此部分编写的代码:
Function NumericOnly(s As String) As String
Dim StrUnit As String
Static re As RegExp
If re Is Nothing Then Set re = New RegExp
re.IgnoreCase = True
re.Global = True
re.Pattern = "GALLON|BOX|#|LF|GAL|EA|CS|BTLS"
StrUnit = re.Replace(s, "")
End Function