zoukankan      html  css  js  c++  java
  • byte转换字符串(string)+字符串转换byte

    C# 中字符串string和字节数组byte[]的转换

    //string转byte[]:
    byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str );
    
    //byte[]转string:
    string str = System.Text.Encoding.Default.GetString ( byteArray );
    
    //string转ASCII byte[]:
    byte[] byteArray = System.Text.Encoding.ASCII.GetBytes ( str );
    
    //ASCII byte[]转string:
    string str = System.Text.Encoding.ASCII.GetString ( byteArray );

    Java中字符串string和字节数组byte[]的转换

    //string 转 byte[]
    
    String str = "Hello";
    
    byte[] srtbyte = str.getBytes();
    
    // byte[] 转 string
    
    String res = new String(srtbyte);
    
    System.out.println(res);
    
    
    //当然还有可以设定编码方式
    的
    
    String str = "hello";
    
    byte[] srtbyte = null;
    
    try {
    
        srtbyte = str.getBytes("UTF-8");
    
        String res = new String(srtbyte,"UTF-8");
    
        System.out.println(res);
    
        } catch (UnsupportedEncodingException e) {
    
        // TODO Auto-generated catch block
    
        e.printStackTrace();
    
        }
  • 相关阅读:
    sss
    stm32cube使用
    FreeRTOS
    嵌入式网站
    CRC分段校验
    IAR编译器
    (转)UCOSII源代码剖析
    (转)stm32硬件IIC
    keil MDK注意事项
    (转).Net中自定义类作为Dictionary的key详解
  • 原文地址:https://www.cnblogs.com/weibanggang/p/10173022.html
Copyright © 2011-2022 走看看