Code 39 Mod 43 Checksum

Published on

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!

Struggling to figure out what to focus on with Blazor?

BlazorSharp - The .NET Web Developers community is here to help!

  • Connect with your fellow .NET web developers
  • Keep up to date with the latest .NET changes
  • Exchange tips, tools and tactics
Join Now