-3

I came across one requirement, in which i have system.byte[] value coming from database. Now i need to get string value from that bye[] values. I am iterating datatable values using datarow. There are so many columns coming with system.byte[] value. How can i check system.byte[] value and convert it into string show as a result?

leppie
  • 115,091
  • 17
  • 196
  • 297
Pradeep atkari
  • 549
  • 1
  • 8
  • 14
  • If i summarize you need to convert byte array to string? And I suppose this is ASP.NEt? visit and check my function might help you http://stackoverflow.com/questions/27498856/how-to-convert-byte-to-string-in-c-sharp/27498904#27498904 – Tushar Gupta Dec 17 '14 at 06:02
  • possible duplicate of [byte\[\] to hex string](http://stackoverflow.com/questions/623104/byte-to-hex-string) – Peter Duniho Dec 17 '14 at 06:33
  • How is the text encoded in those bytes? You need to know that before you can correctly decode the bytes into text. Is it UTF8? UTF16? Ascii? etc. – Lasse V. Karlsen Dec 17 '14 at 08:27

1 Answers1

2

You are asking two questions here : "How to concate" and "How to convert".

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

aloisdg
  • 22,270
  • 6
  • 85
  • 105