关于字符的转换和存储

void testUTF8()
    {
        string aa = "我们很好";
        // toBase64
        string bb = Convert.ToBase64String(Encoding.UTF8.GetBytes(aa));
        print(bb);
        byte[] cc = Convert.FromBase64String(bb);
        string ee = UTF8Encoding.UTF8.GetString(cc);
        print(ee);


        string st = "是肯德基";
        byte[] bytes = UTF8Encoding.UTF8.GetBytes(st);
        //string aa = Convert.ToBase64String(bytes);
        //byte[] cc = Convert.FromBase64String(aa);
        string dd = UTF8Encoding.UTF8.GetString(bytes);
        print(dd);

    }

 void testZip()
    {
        MemoryStream ms = new MemoryStream();
        GZipOutputStream gzip = new GZipOutputStream(ms);
        byte[] binary = Encoding.UTF8.GetBytes("sddddddddd");
        gzip.Write(binary, 0, binary.Length);
        gzip.Close();
        byte[] press = ms.ToArray();
        Debug.Log(Convert.ToBase64String(press) + "  " + press.Length);


        GZipInputStream gzi = new GZipInputStream(new MemoryStream(press));
        MemoryStream re = new MemoryStream();
        int count = 0;
        byte[] data = new byte[4096];
        while ((count = gzi.Read(data, 0, data.Length)) != 0)
        {
            re.Write(data, 0, count);
        }
        byte[] depress = re.ToArray();
        Debug.Log(Encoding.UTF8.GetString(depress));
    }

 public void TestSaveData()
    {
        string str = Application.dataPath + "/test.xls";
        byte[] byData;
        char[] charData;
        try
        {
            FileStream aFile = new FileStream("E:/proj/CMZY/CMZY_TransportTruck/Temp2.txt", FileMode.Create);
            string st = "是肯德基";
            byData = UTF8Encoding.UTF8.GetBytes(st);


            //byData = new byte[charData.Length*2];
            //Encoder e = Encoding.UTF8.GetEncoder();
            // e.GetBytes(charData, 0, charData.Length, byData, 0, true);


            // Move file pointer to beginning of file.
            aFile.Seek(0, SeekOrigin.Begin);
            aFile.Write(byData, 0, byData.Length);
        }
        catch (IOException ex)
        {
            //Console.WriteLine("An IO exception has been thrown!");
            //Console.WriteLine(ex.ToString());
            //Console.ReadKey();
            return;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值