惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
G
Google Developers Blog
博客园 - 司徒正美
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
WordPress大学
WordPress大学
T
The Blog of Author Tim Ferriss
D
Docker
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
M
MIT News - Artificial intelligence
Jina AI
Jina AI
I
InfoQ
雷峰网
雷峰网
The Cloudflare Blog
美团技术团队
Engineering at Meta
Engineering at Meta

博客园 - 沧海一声笑

关于UltraWinGrid选中行只读设置 关于chrome 插件PageMonitor 安装及使用步骤 关于UNICODE字符串的匹配问题 关于string的indexof方法的试验 关于字符串效率问题 抉择 随记一下 关于域用户的AD验证 关于命令模式的一些理解 关于异步委托的部分理解 基于深度优先搜索的蜘蛛程序 观察者模式的简单实现与讨论 下拉框自动回发! 国庆前生活学习计划 2007年总结 看完色戒有感 年前工作计划 Psytopic性格测试! 求助? 关于购买开发用途笔记本的配置 及推荐品牌和型号! 谢谢! 转帖:真爱 就不要等
C# 字符转ASCII码,ASCII码转字符 [转一下]
沧海一声笑 · 2009-08-13 · via 博客园 - 沧海一声笑

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];
    return (intAsciiCode);
   }
   else
   {
    throw new Exception("Character is not valid.");
   }

  }

ASCII码转字符:

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);
    return (strCharacter);
   }
   else
   {
    throw new Exception("ASCII Code is not valid.");
   }
  }

posted on 2009-08-13 23:59  沧海一声笑  阅读(3550)  评论()    收藏  举报