BarcodeLib/Symbologies/Postnet.cs
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using System;
using System.Collections.Generic;
using System.Text;
namespace BarcodeLib
{
class Postnet : BarcodeCommon, IBarcode
{
private string[] POSTNET_Code = { "11000", "00011", "00101", "00110", "01001", "01010", "01100", "10001", "10010", "10100" };
public Postnet(string input)
{
Raw_Data = input;
}//Postnet
/// <summary>
/// Encode the raw data using the PostNet algorithm.
/// </summary>
private string Encode_Postnet()
{
//remove dashes if present
Raw_Data = Raw_Data.Replace("-", "");
switch (Raw_Data.Length)
{
case 5:
case 6:
case 9:
case 11: break;
default: throw new Exception("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
}//switch
//Note: 0 = half bar and 1 = full bar
//initialize the result with the starting bar
string result = "1";
int checkdigitsum = 0;
foreach (char c in Raw_Data)
{
try
{
int index = Convert.ToInt32(c.ToString());
result += POSTNET_Code[index];
checkdigitsum += index;
}//try
catch (Exception ex)
{
throw new Exception("EPOSTNET-2: Invalid data. (Numeric only) --> " + ex.Message);
}//catch
}//foreach
//calculate and add check digit
int temp = checkdigitsum % 10;
int checkdigit = 10 - (temp == 0 ? 10 : temp);
result += POSTNET_Code[checkdigit];
//ending bar
result += "1";
后面还有 13 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。