.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
ffttt
Post New Web Links

Byte array -> String encoding

Posted By:      Posted Date: November 03, 2010    Points: 0   Category :.NET Framework
 
Greetings and sorry for the likely newbie question.  I also hope this is in the right forum!

What's the most "pure" way to encode a Byte array into a String?  I've performed several searches but none have yielded much insight into my particular problem.  I'm using C++, COM Interop into a VB6 application that uses a String return for socket class, but the actual issue is in the .NET native code.

Using:
  Encoding::ASCII->GetString(byteArray, 0, iNumBytes)
.. converts values >7 bits to a replacement value... and

  Encoding::UTF8->GetString(byteArray, 0, iNumBytes)
.. truncates the higher value chars from the conversion totally..

And obviously Unicode things the string is 1/2 it's actual size which makes parsing for markers in said data a real chore.  The byte streams are about 90% text and 10% binary (with markers/tags).

String containers seem to be able to do what I need them to do as manually initializing them, they get back up to the VB6 app without any problems.  It's just how to get these Byte arrays into them that's the problem.

Replacing the VB6.0 app to use something other than String would also be less than ideal as it's usage wasn't coded very managebly either and is widespread in a very, very large application.

The Byte array is from Socket class operations.  I'm unsure if there is a


View Complete Post


More Related Resource Links

encoding/decoding a string to/from bitmap

  

I have two methods:

Encode - takes a string, converts it to array of bytes, uses bytes to specify colors, creates a color and sets a pixel based on bytes

Decode - takes a pixel, retrieves color (R,G,B) bytes and converts them to characters, that produces a string which was previously encoded

I'm using two for loops (img height/width) to specify position and access pixels

The issue is that once display (Control Panel\Appearance and Personalization\Display) changes to anything other then "Smaller - 100%",
bytes have different values during decoding, thus different string is produced (corrupted).

If the setting is set to "Smaller - 100%" the results are normal.

What can I do to avoid that problem?

Thanks in advance


Encoding.ASCII.GetString(bytes) return string with not expected

  
Example   byte[] bytes = {  0x36,0x92,0x30,0x94}; string rs=  Encoding.ASCII.GetString(bytes) ; //result rs = ?60?   Is Wrong Result; Result Right is     '60". So this function should fix to properly decode two symbols ' and " Code ASCII ' is 0x92,Code ACII for " is  0x94

How to String to Array List

  
i have a string like   S="1.2.3.4.5.6."but i want string to convert to Arraylist Ar[0]=1;Ar[1]=2;

how can i get the last chars in a string array...?

  

Hi again,

I am having trouble with parsing a srtring, let me figure out :

This is my string (being gathered from DB) :    students/notes/8293/location/michael.jpg

and i want to parse "michael.jpg" from this string to be able to process it.


problem in passing string array from activex dll to JavaScript

  
Hi,

I do have a problem in passing string array from activex dll to JavaScript. i need to implement a methos as 

C# : 

help encoding a string like this: The%20Best%20Place%20in%20Vancouver

  

how do I convert a string like this: "The Best Place in Vancouver " to this -> The%20Best%20Place%20in%20Vancouver

 

cheers

 

Marc


System.String[*] -> cannot be casted to System.Array

  

Hey

I have been trying to access the synonyms using word interop assemblies. The type returned is of System.String[*].

I have searched the internet for ways to cast it to some type to use it and have tried doing everything including trying to cast it to System.Array.

However, the exception still crops up regarding its inability to convert System.String[*] to System.String[].

Kindly suggest a way out.


Convert comma delimited record to string array

  

Is there any efficient way to convert a comma delimited record with quotes to string array?

Say, "Peter","Pan",123,"Hello, is it ok",Test
str[0] = "Peter"
str[1] = "Pan"
str[2] = 123
str[3] = "Hello, is it ok"
str[4] = "Test"

That is comma within quotes are not treated as delimited

Thanks


How to count number of bytes in string for utf-8 encoding

  

How to find number of bytes in string in utf-8 encoding ?

str.Length returns number of characters but in utf-8 encoding some characters occupy more than 1 byte ? 


Converting ReportDocument object into byte array ?

  

Hi All,

          Is it possible to convert the Report Document object as a byte array and store it in SQL , later retrieve and assing it to a report ?

 


Converting a byte array to a gif

  

Hi there,

I am currently in the process of trying to convert a byte array into a gif format. So far I have done this:

                        byte[] gif = Convert.FromBase64String(myByteArray);
                        MemoryStream ms = new MemoryStream(gif);
                        Bitmap image = new Bitmap(ms);
                        string pathToSave = Server.MapPath("~/_temp/");
                        iconUrl = string.Format("{0}/{1}.gif", pathToSave, fileName);
                        image.Save(iconUrl);


When this code block executes, I get the following error:

A generic error occurred in GDI+.

I have made sure that I have the correct permissions for the _temp folder, but I am not sure if I am trying to convert "bad bytes". Could someone perhaps shed some light on this error? 


Conversion of Byte Array to Memory stream

  

how to convert byte array to memory stream in vb.net.


How to Pass higher Length of Byte Array to the remoting method

  
Dear all,I am using a windows application and the businness logic is present in the remote server.Once particular method takes bytearray as input parameter...Whenever the method call is made the function returns value .This is limited for the particular bytearray length. (4109228 bytes).If the length of bytearray crosses 4109228 bytes.I am getting an error that "input stream is not valid binary format".How to Pass higher Length of Byte Array to the remoting method... Greater than 4 MB?I believe something is missing in web.config or app.config...?What could be the issue...? Any sugesstions are welcome....ThanksRavikumar

how to split byte array

  
hi all,how to split byte array?for eg when i convert byte array to string it will come like as followsbytetostring="%%90,53453%%20,%%20,434234my requirement is i need to split bytearray using the string byte "%%"and need to find out hex value of each linebyte to hex i did like as followsDim strTemp1 As New StringBuilder(Bytes.Length * 2)                                    For intIndex1 = offset To offset + count - 1  'offset is 0 and count is length of the string                                        strTemp1.AppendFormat("{0:x2}", Bytes(intIndex1))                                    Nextthis function resulting the hex value of full string.I need hex value of each byte splitted with "%%"

Converting a System.Windows.Control.Image object to byte array.

  
Hi i need to convert a specific System.Windows.Control.Image object into an (int) array, because i'm trying to convert a silverlight application into a wpf project. private void createGi02GradBrush()<br/> {<br/> WriteableBitmap oWriteableBitmap = new WriteableBitmap(256, 256);<br/> Image oImage = new Image();<br/> oImage.Arrange(new Rect(0, 0, 256, 256));<br/> oImage.Measure(new Size(256, 256));<br/> oImage.Source = new WriteableBitmap(256, 256);<br/> Gi02GradShaderEffect oGi02GradShaderEffect = new Gi02GradShaderEffect();<br/> oGi02GradShaderEffect.pArray = oPImageBrush;<br/> oGi02GradShaderEffect.gi1GradArray = oGi1GradImageBrush;<br/> oImage.Effect = oGi02GradShaderEffect;<br/> oWriteableBitmap.Render(oImage, null);//here<br/> oWriteableBitmap.Invalidate(); <br/> this.oGi02GradImageBrush = new ImageBrush();<br/> this.oGi02GradImageBrush.ImageSource = oWriteableBitmap;<br/> } I've found some similar topics however Image object is not the same and most of its methods aren't available. Here I'm rendering a writablebitmap with a given Image object, but in wpf we need an array. oWriteableBitmap.Render(oImage, null); Any idea? Thanks. Joseph.  

write Data to Byte[ ] array

  
Hi All.i hava a data in string variable for example :string Data = "0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/"and i want to convert this data to binary format so that i can insert this data to Image data field in Database .. can u please give me the solution.Thanks in advance
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend