ASCII码转字符串

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
return (strCharacter);
}
else
{
throw new Exception("ASCII Code is not valid.");
}Baidu Nhomakorabea
}
Excel专用
/// <summary>
/// ASCII码转字符串(转换为Excel列的形式:A/B/C...AA/AB/AC...BA/BB/......)
public static int Asc(string character)
{
if (character.Length == 1)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
}
}
/// </summary>
/// <param name="asciiCode">最大数字255(即Excel最末列IV)</param>
/// <returns></returns>
public static string Chr(int asciiCode)
{
if (asciiCode > 0 && asciiCode <= 255)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
byte[] byteArray = new byte[] { (byte)asciiCode };
string strCharacter = asciiEncoding.GetString(byteArray);
byteArray = new byte[] { (byte)(mod + 64) };
strCharacter = strCharacter + asciiEncoding.GetString(byteArray);
}
return strCharacter;
}
else
{
return "ASCII Code is not valid.";
int mod = (asciiCode - 64) % 26;
if (mod == 0)
{
division = division - 1;
mod = 26;
}
if ((division == 0) && (mod <= 26))
{
byteArray = new byte[] { (byte)(mod + 64) };
strCharacter = strCharacter + asciiEncoding.GetString(byteArray);
}
else
{
byteArray = new byte[] { (byte)(division + 64) };
strCharacter = strCharacter + asciiEncoding.GetString(byteArray);
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
string strCharacter = string.Empty;
byte[] byteArray = null;
int division = (asciiCode - 64) / 26;
return (intAsciiCode);
}
else
{
throw new Exception("Character is not valid.");
}
}
ASCII码转字符:
单个字符
public static string Chr(int asciiCode)
{
if (asciiCode >= 0 && asciiCode <= 255)
相关文档
最新文档