/// <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#编码转换的更多相关文章

  1. 使用vbs脚本进行批量编码转换

    使用vbs脚本进行批量编码转换 最近需要使用SourceInsight查看分析在Linux系统下开发的项目代码,我们知道Linux系统中文本文件默认编码格式是UTF-8,而Windows中文系统中的默 ...

  2. 关于JS的编码转换问题

    在进行JS开发过程中,尤其是在开发报表时,报表已集成到Web页面中,通过在页面传递参数至报表中时,会发现有时某些参数值,传递到报表中是显示为问号或乱码等等一系列不能正常显示的情况. 这是由于浏览器和报 ...

  3. 帆软报表FineReport数据库连接编码转换

    1. 问题描述 数据库会以某种编码方式保存与读取数据,FineReport解析时默认使用GBK字符集,若数据库端编码与设计器端编码不一致时,就会导致中文及特殊字符的乱码. FineReport在定义数 ...

  4. 编码转换的处理 DreamWeaver SC6 打开会出现javacsript出现问题的处理

      编码转换的处理: 打开DW后,修改里面有个"页面属性": 点击页面属性,会弹出一个窗口,点击"标题/编码",在"编码"里面选择你要转换的 ...

  5. C++ 字符编码转换类

    记录一下C++ 编码转换的函数: #pragma once #include "afx.h" #define DEFAULT_CODE 0 #define CHINESE_SIMP ...

  6. [2015.02.02]文本编码转换专家 v2.6

    软件名称:文本编码转换专家最新版本:v2.6操作系统:XP/2003/Win7/Win2008软件介绍:文本编码转换专家,界面简洁易用,功能强大实用.自动识别文件编码,有效转换成目标编码.真正的多线程 ...

  7. python 字符编码 转换

    #!/bin/env python#-*- encoding=utf8 -*-# 文件头指定utf8编码还是乱码时,使用下面方式指定# fix encoding problem import sys ...

  8. ASP 编码转换(乱码问题解决)

    ASP 编码转换(乱码问题解决) 输出前先调用Conversion函数进行编码转换,可以解决乱码问题. 注,“&参数&”为ASP的连接符,这里面很多是直接调用的数据库表字段,实际使用请 ...

  9. Linux查看文件编码格式及文件编码转换

    Linux查看文件编码格式及文件编码转换   如果你需要在Linux 中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而L ...

  10. UTF8编码转换(C#)

    例如: UTF8---ISO-8859-1 string string = "这是中文";Encoding utf8 = Encoding.UTF8; Encoding ISO = ...

随机推荐

  1. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(八)资源搜索模块

    config.xml文件的配置如下: <widget label="资源搜索" icon="assets/images/public_impact_over.png ...

  2. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q135-Q137)

    Question  135 You work for a software company that sells Web Parts to customers. You designed the fi ...

  3. iOS UIMenuController菜单

    //1:普通 ////  ViewController.m//  DemoTest#import "ViewController.h"@interface ViewControll ...

  4. vim插件管理vundle备忘

    转自:http://blog.csdn.net/jiaolongdy/article/details/17889787/ http://www.cnblogs.com/xia520pi/archive ...

  5. fillStyle径向渐变

    <!DOCTYPE HTML> <head> <meta charset = "utf-8"> <title>canvas</ ...

  6. Guest Speaker on 2015 WinHEC Shenzhen 秋季大会

    继今年3月份的WinHEC春季大会,秋季大会于11月10日-11日深圳如期举行.此次大会的主题是Windows 10 IoT和Microsoft Azure,云和端的无缝连接是微软物联网解决方案的典型 ...

  7. RMAN命令LIST操作总结

    在使用RMAN备份.还原的过程中,我们经常需要查看备份的一些详细信息,例如,RMAN提供了LIST命令.关于LIST命令的详细信息 可以参考Oracle Database Backup and Rec ...

  8. [AlwaysOn Availability Groups]DMV和系统目录视图

    DMV和系统目录视图 这里主要介绍AlwaysON的动态管理视图,可以用来监控和排查你的AG. 在AlwaysOn Dashboard,你可以简单的配置的GUI显示很多可用副本的DMV和可用数据库通过 ...

  9. jquery本地上传预览扩展(隐藏上传控件单击图片上传支持ie!!)

    我用到的原材料地址:http://www.cnblogs.com/leejersey/p/3660202.html 修改后: /// <reference path="../../Js ...

  10. js的encodeURIComponent与java的URLEncoder的区别

    js中的encodeURIComponent这个函数和java中的URLEncoder有少数不一样的.如下表格就是区别 ascii java js   + %20 ! %21 ! ' %27 ' ( ...