c# 中文和字符串转成ascii码 和 ascii码转成字符

最近手上在做一个项目,涉及到了编码问题,查了不少资料。下面内容是关于C#中中文和字符串转成ASCII码和ASCII码转成字符的代码

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
static class Module1
{
    public static int ConvertToAscii(char c)
    {
        return Strings.AscW(c);
    }
  
    public static char ConvertFromAscii(int n)
    {
        return Strings.ChrW(n);
    }
    public static void Main()
    {
        //测试
        string s = "我爱北京天安门";
        foreach (char c in s) {
            Console.Write(ConvertToAscii(c).ToString() + "   ");
        }
        Console.WriteLine();
        int[] n = new int[] {
            25105,
            29233,
            21271,
            22825,
            23433,
            38376
        };
        foreach (int num in n) {
            Console.Write(ConvertFromAscii(num).ToString() + "      ");
        }
  
    }
}


参考地址: http://wenwen.soso.com/z/q203180818.htm

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值