/******************************************************************/
/*********************** ****************************/
/*********************** 汉字转换工具 ****************************/
/*********************** ****************************/
/******************************************************************/ /**************************** 字符串转编码函数 **********************************/
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. str*函数和大小端判断

    #include <stdio.h> #include <assert.h> size_t mstrlen(const char *s) { assert(s != NULL) ...

  2. 【原创】Mac上编译Hadoop1.0.3出现的一些问题

    create-native-configure: [exec] configure.ac:47: error: possibly undefined macro: AC_PROG_LIBTOOL [e ...

  3. boj1267 Infinite’s Cave 树形dp + 背包

    题目链接:http://acm.bupt.edu.cn/onlinejudge/newoj/showProblem/show_problem.php?problem_id=1267         / ...

  4. Art Gallery - POJ 1279(求内核面积)

    同上面几道题差不多,需要先求出来内核,然后直接用叉积求出来面积即可. 代码如下: #include<iostream> #include<string.h> #include& ...

  5. hdoj 1242 Rescue

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. C#中异步和多线程的区别

    C#中异步和多线程的区别是什么呢?异步和多线程两者都可以达到避免调用线程阻塞的目的,从而提高软件的可响应性.甚至有些时候我们就认为异步和多线程是等同的概念.但是,异步和多线程还是有一些区别的.而这些区 ...

  7. iOS从生成证书到打包上架-01(详细2016-10最新)

    今天项目上架成功,在此小结一下这个过程,希望对这个流程有疑惑的小伙伴少走弯路(大神请忽略此文) 关于证书是什么,请自行百度,Google,这里直接上流程. 1.首先打开苹果开发者网站,Apple De ...

  8. 写一些有关android的东西吧,那时候玩android时候的一些笔记

    写一些有关android的东西吧,那时候玩android时候的一些笔记

  9. MySQL bug:server-id默认被自己主动置为1

    昨天同事在做主从时,从库报例如以下错误: Got fatal error 1236 from master when reading data from binary log: 'Misconfigu ...

  10. Android多线程研究(4)——从一道面试题说起

    有一道这种面试题:开启一个子线程和主线程同一时候运行,子线程输出10次后接着主线程输出100次,如此重复50次.先看以下代码: package com.maso.test; /** * * @auth ...