/******************************************************************/
/*********************** ****************************/
/*********************** 汉字转换工具 ****************************/
/*********************** ****************************/
/******************************************************************/ /**************************** 字符串转编码函数 **********************************/
private byte[] StringToBytes(string TheString)
{
Encoding encoding = Encoding.GetEncoding("UTF-8");
Encoding encoding2 = Encoding.GetEncoding("gb2312");
byte[] bytes = encoding.GetBytes(TheString);
return Encoding.Convert(encoding, encoding2, bytes);
}
/**************************** 编码转字符串函数 **********************************/
private string BytesToString(byte[] Bytes)
{
Encoding encoding = Encoding.GetEncoding("gb2312");
Encoding encoding2 = Encoding.GetEncoding("UTF-8");
byte[] bytes = Encoding.Convert(encoding, encoding2, Bytes);
return encoding2.GetString(bytes);
}
/**************************** 单击转换按钮事件 **********************************/
private void Changez_Click(object sender, EventArgs e)
{
if (this.CHcode.Checked)//判断什么类型的转换
{
byte[] array = this.StringToBytes(this.intextz.Text);
this.outtextz.Text = "";
byte[] array2 = array;
for (int i = ; i < array2.Length; i++)
{
byte b = array2[i];
string text = b.ToString("x").ToUpper();
TextBox expr_64 = this.outtextz;
expr_64.Text = expr_64.Text + "0x" + ((text.Length == ) ? ("" + text) : text) + " ";
}
}
else
{
if (!this.CHcode.Checked)
{
byte[] array3 = new byte[this.intextz.Text.Length / ];
try
{
string text2 = this.intextz.Text;
text2 = text2.Replace("0x", "");
text2 = text2.Replace(" ", string.Empty);
for (int j = ; j < text2.Length / ; j++)
{
array3[j] = Convert.ToByte(text2.Substring(j * , ), );
}
this.outtextz.Text = this.BytesToString(array3);
}
catch
{
MessageBox.Show("数据转换错误,请输入数字。", "错误");
}
}
}
}

c#汉字与编码之间的转换(输出十六进制)的更多相关文章

  1. 字符编码之间的转换 utf-8 , gbk等,(解决中文字符串乱码)

    目录 1.背景. 2.编码的理解 3.编码之间的相互转化 4. str类型说明 5. 可以使用的编码类型 6.参考文章 1.背景 Python中与其他程序进行交互时,如果存在字符串交互,特别是字符串中 ...

  2. java编写之jpg图片与base64编码之间的转换

    /** * @author zyq * 将网络图片进行Base64位编码 * @param imgUrl * */ public static String encodeWebImageToBase6 ...

  3. 326 集合 ,数据类型的补充 ,copy , 编码之间的转换

    一.数据类型补充1,对于元组:如果只有一个元素,并且没有逗号,此元素是什么数据类型,改表达式就是什么数据类型. tu = () tu1 = (,) print(tu,type(tu)) #1 < ...

  4. utf8、ansii、unicode编码之间的转换

    #include "stdafx.h"#include "windows.h"#include <iostream>#include <str ...

  5. C# - 汉字与unicode之间的转换

    /// <summary> /// 字符串转Unicode码 /// </summary> /// <returns>The to unicode.</ret ...

  6. Java Int类型与字符,汉字之间的转换

    /** * java 中的流主要是分为字节流和字符流 * 再一个角度分析的话可以分为输入流和输出流 * 输入和输出是一个相对的概念 相对的分别是jvm虚拟机的内存大小 * 从另一个角度讲Java或者用 ...

  7. (2)字符编码关系和转换(bytes类型)

    ASCII 占一个字节,只支持英文 GB2312 占2个字节,只支持6700+汉字 GBK 是GB2312的升级版,支持21000+汉字 Shift-JIS 日本字符编码 ks_c-5601-1987 ...

  8. Unicode和UTF-8之间的转换

    转自:http://www.cnblogs.com/xdotnet/archive/2007/11/23/unicode_and_utf8.html#undefined 最近在用VC++开发一个小工具 ...

  9. 汉字编码(【Unicode】 【UTF-8】 【Unicode与UTF-8之间的转换】 【汉字 Unicode 编码范围】【中文标点Unicode码】【GBK编码】【批量获取汉字UNICODE码】)

    Unicode与UTF-8互转(C语言实现):http://blog.csdn.net/tge7618291/article/details/7599902 汉字 Unicode 编码范围:http: ...

随机推荐

  1. 【CSS】Beginner1:Applying CSS

    CSS(Cascading Style Sheets)   1.Applying CSS Three ways: 1.In-line 2.Internal 3.External   2.In-line ...

  2. centos "cannot open display"的问题

    实用技巧:在Linux下设置xhost方法步骤 第一步:用root登陆linux,启动vnc服务: 第二步:根据vnc起来的端口,设置export DISPLAY=localhost:1(1表示vnc ...

  3. HW5.15

    public class Solution { public static void main(String[] args) { System.out.printf("%10s\t%10s\ ...

  4. linux安装svn服务器(yum方式)

    1.查看yum是否安装         在终端中输入yum即可如果已经安装,会显示yum的参数         如果没有安装,会提示yum未安装或无效命令…… 2.安装svnyum -y instal ...

  5. Cocos2d-x MultipleTouch & CCControllButton's confusion

    在cocos2dx的程序设计中有时候会遇到需要多点触摸的功能,下面先介绍一下在cocos2dx中多点触摸的一般规则,然后介绍我遇到的一个有关多点触摸的情景的解决方案. (一)使用多点触摸规则: 关于多 ...

  6. JavaWeb文件的上传与下载(1)

    经常用到的上传: 头像上传,资料分享等 文件上传的步骤 1.指定表单类型为文件上传表单 enctype="multipart/form-data" 2.表单提交方式必须为:post ...

  7. UVA 185(暴力DFS)

      Roman Numerals  The original system of writing numbers used by the early Romans was simple but cum ...

  8. DHTMLX 前端框架 建立你的一个应用程序教程(三)--添加一个菜单

    菜单的介绍 这篇我们介绍将菜单组建添加到上节中的布局中: 我们不对菜单做任何处理  只是在这里填充作为界面的一部分. 这里我们介绍的是dhtmlxMenu 组件. 这个组件的数据我们可以从XML或者J ...

  9. systemtap 列出所有linux 内核模块与相关函数2

    [root@localhost src]# uname -aLinux localhost.localdomain 2.6.32 #1 SMP Sun Sep 20 18:58:21 PDT 2015 ...

  10. ODB 下载与安装 (Linux)

    http://www.codesynthesis.com/products/odb/download.xhtml Installing ODB on UNIX Introduction This gu ...