Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert System.Byte[] to System.String

Posted on 2009-05-10
4
Medium Priority
?
1,069 Views
Last Modified: 2012-05-06
Hi,

I was looking for a solution where I am trying to print the string value but I get the output as System.Byte[].

Is there any way I can convert System.Byte[] to System.String? Looking for solution in C# please...
PdfReader obj_pdf = new PdfReader("http://illiad.evms.edu/sample.pdf");                    
Console.Write(obj_pdf.GetPageContent(1).ToString());
 
Output: 'System.Byte[]' is displayed.
 
I am looking for printing complete text inside this PDF file.

Open in new window

0
Comment
Question by:dev_qasource
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 672 total points
ID: 24351444
0
 
LVL 9

Assisted Solution

by:tculler
tculler earned 664 total points
ID: 24351450
Well I'm not sure what you have here, but I'll see what I can do:
// If you want to get the byte array as a String with the Ascii encoding
//(if not Ascii, choose your encoding from System.Text.Encoding's possiblities), here you go:
 
public static void PrintByteArray(System.Byte[] myByteArray)
{
     System.Console.WriteLine(System.Text.Encoding.ASCII.GetString(myByteArray));
}
 
// If you want the individual numbers of the bytes, you can do something like the following
 
public static void PrintByteArray(System.Byte[] myByteArray)
{
     foreach(System.Byte b in myByteArray)
     {
          System.Console.WriteLine(b.ToString() + " ");
     }
}
 
// Or, yet another, more manual option as a variant to the first...
public static void PrintByteArray(System.Byte[] myByteArray)
{
     foreach(System.Byte b in myByteArray)
     {
          System.Console.WriteLine(((System.Char)b).ToString());
     }
}

Open in new window

0
 
LVL 3

Assisted Solution

by:DreamsTech
DreamsTech earned 664 total points
ID: 24351498
Just confirm the Encoding done in getting the Byte Array ,whether its UTF8 or UTF32 etc. Then use
Encoding.UTF8.GetString(byte []);  

Dont Forget to include the Namespace  "using System.Text;"

See the sample below ,the last line is of ur interest.
string str = "Test";
        string AfterEncode = "";
 
        byte[] T = Encoding.UTF8.GetBytes(str);
 
        AfterEncode = Encoding.UTF8.GetString(T);

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question