c#编码转换
/// <summary> /// URL编码 /// </summary> /// <param name="Source"></param> /// <param name="Encod">是否UTF8</param> /// <param name="toUpper">默认到大写</param> /// <returns></returns> public static string URLEncod(string Source, Encoding Encod, bool toUpper = true) { if (toUpper) { StringBuilder sb = new StringBuilder(); ; i < Source.Length; i++) { string t = Source[i].ToString(); string k = HttpUtility.UrlEncode(t, Encod); if (t == k) sb.Append(t); else sb.Append(k.ToUpper()); } return sb.ToString(); } else return HttpUtility.UrlEncode(Source, Encod); } /// <summary> /// URL解码 /// </summary> /// <param name="Source"></param> /// <param name="Encod">是否UTF8</param> /// <returns></returns> public static string URLDecode(string Source, Encoding Encod) { return HttpUtility.UrlDecode(Source, Encod); }
private void button1_Click(object sender, EventArgs e) { //汉字转为Unicode编码: string hz = textBox1.Text.ToString(); byte[] b=Encoding.Unicode.GetBytes(hz); string o = ""; foreach(var x in b){ o += string.Format("{0:X2}",x) + " "; } textBox2.Text = o; } private void button2_Click(object sender, EventArgs e) { //Unicode编码转为汉字: string cd = textBox2.Text.ToString(); string cd2 = cd.Replace(" ", ""); cd2 = cd2.Replace("\r", ""); cd2 = cd2.Replace("\n", ""); cd2 = cd2.Replace("\r\n", ""); cd2 = cd2.Replace("\t", ""); != ) { MessageBox.Show("Unicode编码为双字节,请删多或补少!确保是二的倍数。"); } else { ; byte[] b = new byte[len]; ; i < cd2.Length;i+= ) { ); b[i/] =(); } string o=Encoding.Unicode.GetString(b); textBox1.Text = o; } } private void button5_Click(object sender, EventArgs e) { //汉字转成GBK十六进制码: string hz = textBox3.Text.ToString(); byte[] gbk = Encoding.GetEncoding("GBK").GetBytes(hz); string s1 = ""; string s1d = ""; foreach(byte b in gbk){ //s1 += Convert.ToString(b, 16)+" "; s1 += string.Format("{0:X2}", b) + " "; s1d += b + " "; toolTip1.SetToolTip(textBox4, s1d); } textBox4.Text = s1; toolTip1.SetToolTip(textBox4, s1d); //汉字转成Unicode十六进制码: byte[] uc = Encoding.Unicode.GetBytes(hz); string s2 = ""; string s2d = ""; foreach (byte b in uc) { //s2 += Convert.ToString(b, 16) + " "; s2 += string.Format("{0:X2}", b) + " "; s2d += b + " "; toolTip1.SetToolTip(textBox5, s2d); } textBox5.Text = s2; toolTip1.SetToolTip(textBox5, s2d); //汉字转成UTF-8十六进制码: byte[] utf8 = Encoding.UTF8.GetBytes(hz); string s3 = ""; string s3d = ""; foreach (byte b in utf8) { //s3 += Convert.ToString(b, 16) + " "; s3 += string.Format("{0:X2}", b) + " "; s3d += b + " "; toolTip1.SetToolTip(textBox6, s3d); } textBox6.Text = s3; toolTip1.SetToolTip(textBox6, s3d); } private void button6_Click(object sender, EventArgs e) { //GBK十六进制码转成汉字: string cd = textBox4.Text.ToString(); string[] b4 = cd.Split(' '); ]; bs[] = (], ); bs[] = (], ); textBox3.Text =Encoding.GetEncoding("GBK").GetString(bs); } private void button7_Click(object sender, EventArgs e) { //Unicode十六进制码转成汉字: string cd = textBox5.Text.ToString(); string[] b5 = cd.Split(' '); ]; bs[] = (], ); bs[] = (], ); textBox3.Text = Encoding.GetEncoding("Unicode").GetString(bs); } private void button8_Click(object sender, EventArgs e) { //UTF-8十六进制码转成汉字: string cd = textBox6.Text.ToString(); string[] b6 = cd.Split(' '); ]; bs[] = (], ); bs[] = (], ); bs[] = (], ); textBox3.Text = Encoding.GetEncoding("UTF-8").GetString(bs); }
c#编码转换的更多相关文章
- 使用vbs脚本进行批量编码转换
使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看分析在Linux系统下开发的项目代码,我们知道Linux系统中文本文件默认编码格式是UTF-8,而Windows中文系统中的默 ...
- 关于JS的编码转换问题
在进行JS开发过程中,尤其是在开发报表时,报表已集成到Web页面中,通过在页面传递参数至报表中时,会发现有时某些参数值,传递到报表中是显示为问号或乱码等等一系列不能正常显示的情况. 这是由于浏览器和报 ...
- 帆软报表FineReport数据库连接编码转换
1. 问题描述 数据库会以某种编码方式保存与读取数据,FineReport解析时默认使用GBK字符集,若数据库端编码与设计器端编码不一致时,就会导致中文及特殊字符的乱码. FineReport在定义数 ...
- 编码转换的处理 DreamWeaver SC6 打开会出现javacsript出现问题的处理
编码转换的处理: 打开DW后,修改里面有个"页面属性": 点击页面属性,会弹出一个窗口,点击"标题/编码",在"编码"里面选择你要转换的 ...
- C++ 字符编码转换类
记录一下C++ 编码转换的函数: #pragma once #include "afx.h" #define DEFAULT_CODE 0 #define CHINESE_SIMP ...
- [2015.02.02]文本编码转换专家 v2.6
软件名称:文本编码转换专家最新版本:v2.6操作系统:XP/2003/Win7/Win2008软件介绍:文本编码转换专家,界面简洁易用,功能强大实用.自动识别文件编码,有效转换成目标编码.真正的多线程 ...
- python 字符编码 转换
#!/bin/env python#-*- encoding=utf8 -*-# 文件头指定utf8编码还是乱码时,使用下面方式指定# fix encoding problem import sys ...
- ASP 编码转换(乱码问题解决)
ASP 编码转换(乱码问题解决) 输出前先调用Conversion函数进行编码转换,可以解决乱码问题. 注,“&参数&”为ASP的连接符,这里面很多是直接调用的数据库表字段,实际使用请 ...
- Linux查看文件编码格式及文件编码转换
Linux查看文件编码格式及文件编码转换 如果你需要在Linux 中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而L ...
- UTF8编码转换(C#)
例如: UTF8---ISO-8859-1 string string = "这是中文";Encoding utf8 = Encoding.UTF8; Encoding ISO = ...
随机推荐
- Atitit.加密算法ati Aes的框架设计
Atitit.加密算法ati Aes的框架设计 版本进化 c:\1t\aesC47.java c:\1t\aes.java 增加了public static byte[] encrypt(byte[] ...
- JAVA模板方法设计模式(从现实生活角度理解代码原理)
概述: 定义一个功能的框架(骨架),一部分功能是确定的,一部分功能是不确定的,先把确定的部分实现,把不确定的部分延迟到子类中实现. 实现该模式的关键步骤: 第一步:抽象类,实现模板方法,定义功能(确定 ...
- 触屏touchstart 与 click
设计效果:当手指点击或触摸红框线menuList之外的部分时,弹框menuList消失. 问题:在优化触屏版的时候发现如图问题,当menuList弹出,手指触摸屏幕向下滑动时,menuList弹框不消 ...
- vim easy-align插件使用
https://github.com/junegunn/vim-easy-align 用vundle安装, 添加下面到vimrc Plugin 'junegunn/vim-easy-align' &q ...
- C#.NET万能数据库访问封装类(ACCESS、SQLServer、Oracle)
using System; using System.Collections; using System.Collections.Specialized; using System.Data; usi ...
- Linux NetHogs监控工具介绍
NetHogs介绍 NetHogs是一款开源.免费的,终端下的网络流量监控工具,它可监控Linux的进程或应用程序的网络流量.NetHogs只能实时监控进程的网络带宽占用情况.NetHogs支持IPv ...
- shell实现SSH自动登陆
h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h ...
- Python简单爬虫入门一
为大家介绍一个简单的爬虫工具BeautifulSoup BeautifulSoup拥有强大的解析网页及查找元素的功能本次测试环境为python3.4(由于python2.7编码格式问题) 此工具在搜索 ...
- Si2151/41 6th Generation Silicon TV Tuner ICs
The Si2151/41 are the industry's most advanced silicon TV tuner ICs supporting all worldwide terre ...
- EF高级应用
UpdateSourceTrigger NumberTextbox 参考 Finally! Entity Framework working in fully disconne ...