We have a department in the organization that was given a limited-length description field in a legacy application. They came up with their own acronyms and abbreviations for various phrases, which we would like to convert back to English phrases.
I'd like to have a better way to parse these descriptions than what I'm currently doing.
Sample Items:
Part #: Description
-------------------------------------
10001 17OH 2P 2G TRK 2YR
10002 22OH 2P 3G TRK 1YR
In these sample descriptions, I need to parse these to pull the following items:
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
The legacy application is written in VBScript/Classic ASP, and so the following would be an example of a way to convert these to English.
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)
The output would be:
17 Ohm 2 Pole 2 Gang Track 2-Year Warranty
This would be fine if we just had a dozen or so items to parse out, but we probably have hundreds of these and the repetition of the "if instr" statements are surely hugely inefficient even if we're only running that code a couple hundred times per day. Is there a better way to do this using an array or Regex, or anything more efficient than the above?
Replacefunction. See: stackoverflow.com/a/14973169