111,126
社区成员
发帖
与我相关
我的任务
分享private void btnconvert_Click(object sender, EventArgs e)
{
string sSou = txtyuanwenjian.Text;
Encoding CnEnconding = Encoding.GetEncoding("GB2312");
byte[] bSou = CnEnconding.GetBytes(sSou); //转成数组
for (int i = 0; i < bSou.Length; i++)
{
string strvalue = convertting(bSou[i].ToString(), 10, 2);
if (strvalue.Length <= 8)
{
int cha = 8 - strvalue.Length ;
for (int j = 0; j < cha; j++)
{
strvalue = strvalue.Insert(0, "0");
}
}
txtzhuanhuan.Text = txtzhuanhuan.Text + strvalue; //依次取得
} public string convertting(string value, int baseform, int tobase)
{
long intvalue = Convert.ToInt64(value, baseform);
return Convert.ToString(intvalue, tobase);
}
private void button1_Click(object sender, EventArgs e)
{
string str2 = txtzhuanhuan.Text.Trim();
for (int x = 0; x < str2.Length; x++)
{
if (str2.Substring(0, 1) == "0")
{
string str0 = str2.Substring(x, 8);
string shijinzhi = convertting(str0, 2, 10);
txtchar.Text = txtchar.Text + Convert.ToChar(Convert.ToInt32(shijinzhi)).ToString();
x = x + 7;
}
else
{
string str0 = str2.Substring(x, 16);
string shijinzhi = convertting(str0, 2, 10);
txtchar.Text = txtchar.Text + Convert.ToChar(Convert.ToInt32(shijinzhi));
x = x + 15;
}
}
using System;
using System.Text;
namespace ConvertExample
{
class ConvertExampleClass
{
static void Main()
{
string unicodeString = "This string contains the unicode character Pi(\u03a0)";
// Create two different encodings.
Encoding ascii = Encoding.ASCII;
Encoding unicode = Encoding.Unicode;
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(unicodeString);
// Perform the conversion from one encoding to the other.
byte[] asciiBytes = Encoding.Convert(unicode, ascii, unicodeBytes);
// Convert the new byte[] into a char[] and then into a string.
// This is a slightly different approach to converting to illustrate
// the use of GetCharCount/GetChars.
char[] asciiChars = new char[ascii.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string asciiString = new string(asciiChars);
// Display the strings created before and after the conversion.
Console.WriteLine("Original string: {0}", unicodeString);
Console.WriteLine("Ascii converted string: {0}", asciiString);
}
}
}
public static byte[] Convert(Encoding srcEncoding,Encoding dstEncoding,byte[] bytes)