【问题标题】:c# concatenate byte[] and get string resultc# 连接 byte[] 并获取字符串结果
【发布时间】:2014-12-17 05:59:25
【问题描述】:

我遇到了一项要求,其中我有来自数据库的 system.byte[] 值。 现在我需要从 bye[] 值中获取字符串值。 我正在使用 datarow 迭代 datatable 值。 有很多列带有 system.byte[] 值。 如何检查 system.byte[] 值并将其转换为字符串显示结果?

【问题讨论】:

  • 如果我总结一下您需要将字节数组转换为字符串吗?我想这是 ASP.NET?访问并检查我的功能可能会对您有所帮助stackoverflow.com/questions/27498856/…
  • byte[] to hex string的可能重复
  • 这些字节中的文本是如何编码的?在将字节正确解码为文本之前,您需要知道这一点。是UTF8吗? UTF16? ASCII?等

标签: c# bytearray bytecode concat bitconverter


【解决方案1】:

您在这里问两个问题:“如何连接”和“如何转换”。

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        byte[] bytes1 = { 97, 98, 99, 100 };
        byte[] bytes2 = { 49, 50, 51, 52 };

        // concat
        byte[] bytes = bytes1.Concat(bytes2).ToArray();
        // convert
        string bytesAsString = Encoding.UTF8.GetString(bytes);

        Console.WriteLine(bytesAsString);

    }
}

Demo DotNetFiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 2013-03-08
    • 1970-01-01
    相关资源
    最近更新 更多