我们在组织中有一个部门,在遗留应用程序中为其提供了一个长度有限的描述字段。他们为不同的短语想出了他们自己的缩写和缩写,我们想把它们转换回英语短语。
我希望有一种比我目前正在做的更好的方式来解析这些描述。
示例项目:
Part #: Description
-------------------------------------
10001 17OH 2P 2G TRK 2YR
10002 22OH 2P 3G TRK 1YR在这些示例描述中,我需要解析它们以提取以下项:
17OH = 17 Ohm
22OH = 22 Ohm
2P = 2 Pole
2G = 2-Gang
3G = 3-Gang
TRK = Track
2YR = 2-Year Warranty
1YR = 1-Year Warranty遗留应用程序是用VBScript/Classic ASP编写的,因此下面是将它们转换为英语的一个示例。
descriptionOUTPUT = ""
descriptionRAW = "17OH 2P 2G TRK 2YR"
if instr(descriptionRAW,"17OH") > 0 then descriptionOUTPUT = descriptionOUTPUT & "17 Ohm "
if instr(descriptionRAW,"22OH") > 0 then descriptionOUTPUT = descriptionOUTPUT & "22 Ohm "
if instr(descriptionRAW,"2P") > 0 then descriptionOUTPUT = descriptionOUTPUT & "2 Pole "
if instr(descriptionRAW,"2G") > 0 then descriptionOUTPUT = descriptionOUTPUT & "2 Gang "
if instr(descriptionRAW,"3G") > 0 then descriptionOUTPUT = descriptionOUTPUT & "3 Gang "
if instr(descriptionRAW,"TRK") > 0 then descriptionOUTPUT = descriptionOUTPUT & "Track "
if instr(descriptionRAW,"2YR") > 0 then descriptionOUTPUT = descriptionOUTPUT & "2-Year Warranty "
if instr(descriptionRAW,"1YR") > 0 then descriptionOUTPUT = descriptionOUTPUT & "1-Year Warranty "
response.write(descriptionOUTPUT)输出将为:
17 Ohm 2 Pole 2 Gang Track 2-Year Warranty如果我们只有12个左右的项目需要解析,这是很好的,但我们可能有数百个这样的项目,重复"if instr“语句肯定是非常低效的,即使我们每天只运行该代码几百次。有没有更好的方法使用数组或正则表达式,或者比上面更高效的方法?
发布于 2020-09-07 00:45:29
一种非常基本的方法是在asp中使用字典对象。要么对它们进行硬编码,要么从数据库中读取它们并进行循环比较。
https://stackoverflow.com/questions/63758381
复制相似问题