string与byte[]相互转换方法

简介:         public static string ByteArray2String(byte[] contentByte)         {             string result = string.

  1.         public static string ByteArray2String(byte[] contentByte)
  2.         {
  3.             string result = string.Empty;
  4.             if(contentByte != null)
  5.                 result = Encoding.GetEncoding("UTF-8").GetString(contentByte, 0, contentByte.Length);

  6.             return result;
  7.         }


  8.         public static byte[] String2ByteArray(string documentText)//(Editor myEditor)
  9.         {
  10.             byte[] contentBytes = null;

  11.             /*!!! myEditor.Html中的IMAGE是路径,BodyHtml中的是转换后byte[],但bodyhtml只包含body内的html,
  12.              取整个文件的html需要使用DocumentText */
  13.             if (string.IsNullOrWhiteSpace(documentText))
  14.                 contentBytes = null;
  15.             else
  16.                 contentBytes = Encoding.GetEncoding("UTF-8").GetBytes(documentText);

  17.             return contentBytes;
  18.         }

相关文章
|
2月前
正则表达式(有关String当中,有关正则的方法)
正则表达式(有关String当中,有关正则的方法)
|
5天前
|
数据安全/隐私保护
作用域通信对象:session用户在登录时通过`void setAttribute(String name,Object value)`方法设置用户名和密码。点击登录按钮后,跳转到另外一个页面显示用户
该博客文章通过示例演示了如何使用session对象的`setAttribute`和`getAttribute`方法在不同页面间传递和显示用户的用户名和密码信息,并说明了如何设置会话的有效期。
作用域通信对象:session用户在登录时通过`void setAttribute(String name,Object value)`方法设置用户名和密码。点击登录按钮后,跳转到另外一个页面显示用户
|
11天前
|
存储 Go 索引
Golang 中的 String、rune 和 byte
Golang 中的 String、rune 和 byte
|
14天前
|
测试技术 Go API
golang []byte和string的高性能转换
golang []byte和string的高性能转换
25 1
|
20天前
|
Java
Java中将保留四位小数的Double转换为String的方法详解
选择合适的方法,可以使代码更加简洁、高效,同时也能满足不同场景下的需求。
21 5
|
4天前
|
Dragonfly Dart NoSQL
Dart ffi 使用问题之在Dart中调用String的toNativeUtf8方法时有什么是需要注意的
Dart ffi 使用问题之在Dart中调用String的toNativeUtf8方法时有什么是需要注意的
|
27天前
|
XML Java API
List与String相互转化的方法有哪些
摘要:本文概述了Java中List转换为String及反之的多种策略。使用`String.join()`可简洁地连接List元素;`StringBuilder`提供灵活控制;Java 8 Stream API收集器简化操作;Apache Commons Lang3的`StringUtils.join()`和Guava的`Joiner.on()`支持外部库的高效转换。
|
1月前
|
安全 Java 索引
带你快速掌握Java中的String类和StringBuffer类(详解常用方法 | 区别 )
带你快速掌握Java中的String类和StringBuffer类(详解常用方法 | 区别 )
|
2月前
|
Java 数据处理 Apache
探讨Java中判断String类型为空和null的方法
探讨Java中判断String类型为空和null的方法
24 1
new String()定义字符串为空,char[] chs = {‘a‘,‘b‘,‘c‘} String s2 = new String(chs) 输出abc,byte定99为a
new String()定义字符串为空,char[] chs = {‘a‘,‘b‘,‘c‘} String s2 = new String(chs) 输出abc,byte定99为a