regex - Searching through text for a pattern and replacing the entire pattern in VB.NET -
I am fully collecting information from the Internet to see how to pattern a pattern through a string of text and She has to change something else with it.
I am just starting to learn about RegEx and how to use them, as I think it is best that fits in my needs for the application. Actually what should I do that a string is read from a text file, which can have definitions of 3 ZPL II labels, and change some commands / parameters, by passing all the data to a wireless label printer first.
For example, I need to find the Media Dark Command, ^ MDxx, where xx is an integer that will set the darkness for the printed label. Xx can be negative, positive, and up to but always does not have 2 digits (range-30 to 30) Therefore, a special MD command can be from 4 to 7 characters, and each label can vary for definition, at which I am processing once. I need to replace these three orders with ^ MD-13.
This is a code based on my research, and it is curious to know if I am doing something wrong or if any adjustments need to be done.
Monitoring ^ MNA, B - ^ after a single letter for MN, and alternatively the second letter of a comma lstPatterns.Add ("\ ^ MN [A-Za-z] (\, [A-Za- Z]) "Media Dark" MD "- an optional dash (for negative values) and up to two digits (" see ") Valid values are 30 to 30) refer to lstPatterns.Add ("See ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^" ^ ^ "for MD ^ 12?", "MD-13") for label home ^ LHX, Y ^ LH, five digits, one comma and five digits up to the second number (valid values up to 32000) lstPatterns.Add ("\ ^ LH \ d {1,5}, \ d {1,5}", " ^ LH5,0 ") 'print rate ^ PRA, B, C - ^ Find the PR for two letters / numbers, and two alternate sets of commas with two letters / numbers (valid values of all three parameters AE or 1-14) LstPatterns.Add ("\ ^ PR [A-Ea-e0- 9] {1,2} (\, [A-Ea-e0- 9] {1,2})? (\, [A-EA-e0-9] {1,2})? "," ^ PR2 ") Dim regexp System.Text.RegularExpressions.Regex as lstPatterns regexp = new System.Text.RegularExpressions.Regex (pattern.Key for each pattern) strZPL = RegExp.Replace (strZPL, pattern.Value) Try the end return as the next catch up exception MsgBox (ex.ToString). StrZPL termination function
Where the strInput parameter is a string in which the string of content is ZPL II file (hence 1 3 labels can be included anywhere) I know that the commands will always be there, just right for the wireless printer I am not working with Ting.
Edit: The following is a sample ZPL file that can be processed with this argument. Usually there are too many ^ FO commands, but because it contains sensitive information, I have copied and replaced some commands (they are all the same commands, just with different text values).
~ JO ^ XA ^ EG ^ XZ ^ XA ^ PMN ^ MNY 'Need to find this ^ mm ^ ^ MTD ^ MD20' Need to find it ^ LH10,10 'this ^ LL1119 ^ PR6 'need to find this ^ JMA ^ FO2, 492 ^ FR ^ GB785,2,2 ^ FS ^ FO 8,725 ^ FR ^ GB 785,12,12 ^ FS ^ FO 8,864 ^ FR ^ GB 785,2 2 fs ^ FO 8.10 9 1 FR ^ GB 785,l2 12 ^ fs ^ FO275,492 ^ FR ^ GB2,232,2 ^ fs ^ FO51,51 ^ CI0 ^ A0N, 26,22 ^ FR ^ ^ FDCustomerName FS ^ FO51,81 ^ CI0 ^ A0N, 26,26 ^ FR ^ FDCompanyName ^ fs ^ FO51,111 ^^ CI0 ^ A0N, 26,26 ^ FR ^ FDPhoneNumber ^ fs ^ FO51,142 ^ CI0 ^ A0N, 26,26 the ^ FR ^ FDAddress ^ fs ^ FO51,173 ^ CI0 ^ A0N, 26,26 ^ FR ^ FDCityStateZip ^ fs ^ PQ1 ^ XZ ~ JO ^ XA ^ Easy ^ XZ ^ XA ^ PMN ^ mny this ^ LH0,0 ' Need to find the need 'this ^ MMT ^ M Need to find the CD ^ MD30 'This ^ LL1219 ^ PR6' to find this ^ JMA ^ FO341,51 ^ FR ^ GB2, 1952 ^ FS ^ FO 51,248 ^ FR ^ BB 709.22 FS ^ FO 611172 ^ FR ^ GB 70, 2,2 ^ FS ^ FO 467,250 ^ FR ^ GB 2171.2 FS ^ FO 61,538 ^ FR ^ BB 709, 2 2 2 2 FS ^ FO 508,538 FR ^ GB2 , 293,2 ^ FS ^ FO 61, 417 ^ FR ^ GB 70.22 ^ FS ^ FO 61,831 ^ Fra ^ GB 709.22 ^ FS ^ FO 51,51 ci 0 ^ A, 26, 22 ^ FR ^ FD C customer name fs ^ FO 51.81 CI 0 ^ A0N, 26,26 ^ FR ^ FDCompanyName ^ fs ^ FO51,111 ^^ CI0 ^ A0N, 26,26 ^ FR ^ ^ FDPhoneNumber FS FO5l,l42 ^ ^ ^ CI0 A0N, 26.26 ^ FR ^ FDAddress ^ fs ^ FO51, 173 ^ CI 0 ^ A0 N, 26.26 ^ FR ^ Fdisitistet ZIP ^ fs ^ PQ 1 ^ Aksjh
< / Pre>
Comments
Post a Comment