条码39Code函数
/**/
/*---------------------------------------------------------------------*/
/**/
/* Function: Code39 - applies to Morovia Code39 Fontware */
/**/
/* Code39(text) Converts the input text into a Code 39 barcode string. The */
/**/
/* function throws off characters not in the Code 39 character set, */
/**/
/* and adds start/stop characters. */
/**/
/*----------------------------------------------------------------------*/
public string Code39(string szInpara)
{
int i, nPos;
string szBuffer = "";
string szCharSet = "0123456789.+-/ $%ABCDEFGHIJKLMNOPQRSTUVWXYZ";
i = 0;
while (i < szInpara.Length)
{
nPos = szCharSet.IndexOf(szInpara[i]);
if (szInpara[i] == ' ')
szBuffer += "=";
else if (nPos >= 0)
szBuffer += szInpara[i];
i = i + 1;
}
return "*" + szBuffer + "*";
}
/**/
/*--------------------------Code39Mod43---------------------------------------*/
/**/
/*Converts the input text into a Code39 extended symbol. This function */
/**/
/*should be used to format Morovia code39 font, not Code39 full ASCII font.*/
/**/
/*The text can be any combinations of ASCII characters. Note that the symbol */
/**/
/*generated is an extended Code39, and the scanner must be put in Code39 */
/**/
/*extended mode to read the symbol properly.*/
/**/
/*----------------------------------------------------------------------------*/
public string Code39Mod43(string szInpara)
{
int i = 0, nPos, nCheckSum = 0;
string inPara = "";
string szBuffer = "";
string szSwap = "";
string szCharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%";
string szMappingSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.=$/+%";
i = 0;
inPara = szInpara;
while (i < inPara.Length)
{
nPos = szCharSet.IndexOf(inPara[i]);
if (nPos >= 0)
{
szBuffer += szMappingSet[nPos];
nCheckSum = nCheckSum + nPos;
}
i = i + 1;
}
nCheckSum = nCheckSum % 43;
szSwap = '*' + szBuffer + szMappingSet[nCheckSum] + '*';
return szSwap;
}
/**/
/*--------------------------------Code39Ascii----------------------------------------------*/
/**/
/*Converts the input text into a Code39 extended symbol. This function should be */
/**/
/*used to format Morovia code39 font, not Code39 full ASCII font. The text can be*/
/**/
/*any combinations of ASCII characters. Note that the symbol generated is an extended*/
/**/
/*Code39, and the scanner must be put in Code39 extended mode to read the symbol properly.*/
/**/
/*-----------------------------------------------------------------------------------------*/
public string Code39Ascii(string szInpara)
{
int i = 0, nPos;
string szBuffer = "";
string szSpecial = "";
string szWap = "";
szSpecial = SpecialChar(szInpara);
szInpara = szSpecial;
string szCharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. " + (char)240;
string szMappingSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.=" + (char)240;
while (i < szInpara.Length)
{
nPos = szCharSet.IndexOf(szInpara[i]);
if (nPos >= 0)
szBuffer += szMappingSet[nPos];
else if (szInpara[i] == 0)
szBuffer += "%U";
else if (szInpara[i] == ' ') //control characters
szBuffer += '=';
else if (szInpara[i] == '/')
szBuffer += "/O";
else if (szInpara[i] == ':')
szBuffer += "/Z";
else if (szInpara[i] == 64)
szBuffer += "%V";
else if (szInpara[i] == 96)
szBuffer += "%W";
else if (szInpara[i] > 0 && szInpara[i] <= 26)
{
szBuffer += '$';
szBuffer += (char)(szInpara[i] + 'A' - 1);
}
else if (szInpara[i] > 32 && szInpara[i] <= 46)
{
szBuffer += '/';
szBuffer += (char)((szInpara[i] % 32) + 'A' - 1);
}
else if (szInpara[i] >= 97 && szInpara[i] <= 122)
{
szBuffer += '+';
szBuffer += (char)((szInpara[i] % 32) + 'A' - 1);
}
else if (szInpara[i] >= 27 && szInpara[i] <= 31)
{
szBuffer += '%';
szBuffer += (char)(szInpara[i] - 27 + 'A');
}
else if (szInpara[i] >= 59 && szInpara[i] <= 63)
{
szBuffer += '%';
szBuffer += (char)(szInpara[i] - 59 + 'F');
}
else if (szInpara[i] >= 91 && szInpara[i] <= 95)
{
szBuffer += '%';
szBuffer += (char)(szInpara[i] - 91 + 'K');
}
else if (szInpara[i] >= 123 && szInpara[i] <= 127)
{
szBuffer += '%';
szBuffer += (char)(szInpara[i] - 123 + 'P');
}
i = i + 1;
}
//replace NULL char
i = 0;
while (i < szBuffer.Length)
{
if (szBuffer[i] == 240)
szWap += "%U";
else
szWap += szBuffer[i];
i++;
}
return '[' + szWap + ']';
}
/**/
/*---------------------------------Code39Extended------------------------------------*/
/**/
/*Converts the input text into a Code39 extended symbol. It accepts any ASCII */
/**/
/*characters as input. The only difference from function Code39Ascii is the former */
/**/
/*is designed to work with Morovia Code39(Full ASCII) font and the latter is designed*/
/**/
/*to work with Morovia Code39 font.*/
/**/
/*-----------------------------------------------------------------------------------*/
public string Code39Extended(string szInpara)
{
int i = 0; char ch;
string szSwap = "";
string szSpecial = "";
string szOutPut = "";
szSpecial = SpecialChar(szInpara);
szSwap = szSpecial;
for (i = 0; i < szSwap.Length; i++)
{
ch = szSwap[i];
if (ch == 240)
szOutPut += (char)0xC0;
else if (ch > 0 && ch <= 0x1F)
szOutPut += (char)(0xC0 + ch);
else if (ch == ' ') //space is mapped to equal sign
szOutPut += '=';
else if (ch == '*')
szOutPut += (char)0xF4;
else if (ch == '=')
szOutPut += (char)0xF0;
else if (ch == '[')
szOutPut += (char)0xF1;
else if (ch == ']')
szOutPut += (char)0xF2;
else if (ch == 0x7F)
szOutPut += (char)0xE0;
else
szOutPut += ch;
}
szOutPut = '[' + szOutPut + ']';
return szOutPut;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架