C # code generation (III)-three simple code128 implementations

Source: Internet
Author: User
Tags check character

When writing these three types of bar codes, Baidu came to Baidu on the Internet, that is, no clear definition of code128a, code128b, and code128c was found, then, according to the general statement on the internet, only the corresponding character set is used to write this part.Code

Codea

Public class code128a: abscode128 {// <summary> // code128a barcode. Only the 128 Character Set A (numbers, uppercase letters, and control characters) is supported) /// </Summary> /// <Param name = "encodeddata"> </param> Public code128a (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {// the ASCII code range of Character Set A is 0 ~ 95 foreach (char C in this. _ rawdata) {byte tempc = (byte) C; If (tempc <= 95) {continue;} else {return false ;}} return true;} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.starta]); // Add the start character starta byte sindex; int checknum = code128.starta; // check character for (INT I = 0; I <this. _ rawdata. length; I ++) {sindex = code128.getsindexfroma (this. _ rawdata [I]); tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}

code128b

/// <Summary> /// code128b barcode. Only the 128 Character Set B (numbers, letters, and characters) is supported. /// </Summary> public class code128b: abscode128 {public code128b (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {// the ASCII code range of Character Set B is 32 ~ 127 foreach (char C in this. _ rawdata) {byte tempc = (byte) C; If (tempc >=32 & tempc <= 127) {continue;} else {return false;} return true ;} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.startb]); // Add the start character startb byte sindex; int checknum = code128.startb; // check the character for (INT I = 0; I <this. _ rawdata. length; I ++) {sindex = code128.getsindexfromb (this. _ rawdata [I]); // the ASCII code in Character Set B minus 32, which is equal to the character value tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}

code128c

/// <Summary> // code128c barcode. Only the 128 character set C (double digit) is supported. /// </Summary> public class code128c: abscode128 {public code128c (string rawdata): Base (rawdata) {} protected override bool rawdatacheck () {return RegEx. ismatch (this. _ rawdata, @ "^ \ D {2, 96} $") & this. _ rawdata. length % 2 = 0; // code128c two digits represent a data character, so a maximum of 96 digits can be entered.} protected override string getencodeddata () {stringbuilder tempbuilder = new stringbuilder (); tempbuilder. append (code128.bslist [code128.startc]); // Add the start character startc byte sindex; int checknum = code128.startc; // check character, startc is 105 for (INT I = 0; I <this. _ rawdata. length/2; I ++) {sindex = byte. parse (this. _ rawdata. substring (I * 2, 2); tempbuilder. append (code128.bslist [sindex]); checknum + = (I + 1) * sindex;} checknum % = 103; tempbuilder. append (code128.bslist [checknum]); // Add the verification character tempbuilder. append (code128.bslist [code128.stop]); // Add the terminator return tempbuilder. tostring ();}}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.