- internal class clsVB
- {
- internal static string Chr(int p_intByte)
- {
- if( (p_intByte < 0) || (p_intByte > 255) )
- {
- throw new ArgumentOutOfRangeException("p_intByte", p_intByte, "Must be between 1 and 255.");
- }
- byte[] bytBuffer = new byte[]{(byte) p_intByte};
- return Encoding.GetEncoding(1252).GetString(bytBuffer);
- }
- internal static int Asc(string p_strChar)
- {
- if( (p_strChar.Length == 0) || (p_strChar.Length > 1) )
- {
- throw new ArgumentOutOfRangeException("p_strChar", p_strChar, "Must be a single character.");
- }
- char[] chrBuffer = {Convert.ToChar(p_strChar)};
- byte[] bytBuffer = Encoding.GetEncoding(1252).GetBytes(chrBuffer);
- return (int) bytBuffer[0];
- }
- }
用C#实现Chr and Asc功能
最新推荐文章于 2023-02-02 11:26:14 发布
本文介绍了一个内部类clsVB中的两个静态方法:Chr用于将整数转换为对应ASCII字符,Asc用于获取单个字符的ASCII值。这两个方法通过检查参数的有效性并利用Encoding类来实现字符与整数之间的转换。
1719

被折叠的 条评论
为什么被折叠?



