Code 39 Mod 43 Checksum
July 31, 2008 · 1 minute read
I needed to do some work with barcodes recently, specifically I needed to handle Code 39 Mod 43 barcodes.
Given a barcode string this function should return the relevant Mod 43 checksum.
- public class Code39
- {
- ///
- ///Returns the expected checksum for the specified barcode
- ///
- ///
- ///
- public string ValidateMod43(string barcode)
- {
- int subtotal = 0;
- const string charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
- for (int i = 0; i < barcode.Length; i++)
- {
- subtotal += charSet.IndexOf(barcode.Substring(i, 1));
- }
- return charSet.Substring(subtotal%43, 1);
- }
- }
I adapted this from a VBA script so if there’s a better way of doing it let me know!