473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Encoding.ASCII.GetString question

cok

Hi, All

I have a question about Encoding.ASCII.GetString.

I want convert a byte array to a string, I use
Encoding.ASCII.GetString(byteArray)
(byteArray is something like ['A', 'B', 'C', 0,0,0,0,...])

but the retult is a long string contain string("ABC") and many '0',

How can I only get string "ABC" of I needed?

or May I shouldn't use Encoding.ASCII.GetString ?

thanks for any advice.
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/
_/ Nie Longhai , coder -_-|||
_/ Shanghai Xomi Instruments Co., Ltd.
_/ URL: http://www.xomi.cn
_/ Shanghai C&U Industrial Park
_/ Feng Cheng Town, Feng Xian District
_/ Shanghai, 201411
_/ Phone:86-21-57513966-807
_/ Fax:86-21-57513636
_/ Mobile:13162055440
_/ Email:Ni***@xomi.cn ,co****@163.com
_/
_/ Profession & Focus
_/ High precision semiconductor metrology system vendor.
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Jun 19 '06 #1
4 14295
Encoding.ASCII.GetString(byteArray, 0, Array.IndexOf(byteArray, (byte)
0));
cok wrote:
Hi, All

I have a question about Encoding.ASCII.GetString.

I want convert a byte array to a string, I use
Encoding.ASCII.GetString(byteArray)
(byteArray is something like ['A', 'B', 'C', 0,0,0,0,...])

but the retult is a long string contain string("ABC") and many '0',


Jun 19 '06 #2
Are you getting this string from an imported (windows dll) function or
something? The GetString function isn't designed to look at null
terminated strings.

One way to sort this would be to search through the byte array for the
first value which = null. Then, just convert the previous part of the
array to a string.

-Rich
cok wrote:
Hi, All

I have a question about Encoding.ASCII.GetString.

I want convert a byte array to a string, I use
Encoding.ASCII.GetString(byteArray)
(byteArray is something like ['A', 'B', 'C', 0,0,0,0,...])

but the retult is a long string contain string("ABC") and many '0',

How can I only get string "ABC" of I needed?

or May I shouldn't use Encoding.ASCII.GetString ?

thanks for any advice.
--
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/
_/ Nie Longhai , coder -_-|||
_/ Shanghai Xomi Instruments Co., Ltd.
_/ URL: http://www.xomi.cn
_/ Shanghai C&U Industrial Park
_/ Feng Cheng Town, Feng Xian District
_/ Shanghai, 201411
_/ Phone:86-21-57513966-807
_/ Fax:86-21-57513636
_/ Mobile:13162055440
_/ Email:Ni***@xomi.cn ,co****@163.com
_/
_/ Profession & Focus
_/ High precision semiconductor metrology system vendor.
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


Jun 19 '06 #3
ri**************@gmail.com wrote:
One way to sort this would be to search through the byte array for the
first value which = null. Then, just convert the previous part of the
array to a string.


Search through the byte array for the first value which = (byte) 0,
which is different from null.

Jun 19 '06 #4
cok
Hi, james
thanks for your help :)

<ja**********@gmail.com>
??????:11*********************@h76g2000cwa.googleg roups.com...
Encoding.ASCII.GetString(byteArray, 0, Array.IndexOf(byteArray, (byte)
0));
cok wrote:
Hi, All

I have a question about Encoding.ASCII.GetString.

I want convert a byte array to a string, I use
Encoding.ASCII.GetString(byteArray)
(byteArray is something like ['A', 'B', 'C', 0,0,0,0,...])

but the retult is a long string contain string("ABC") and many '0',

Jun 19 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Viorel | last post by:
For me is a little bit mysterious how work encoding and decoding functions, what is underneath of their calling? Encoding1.GetBytes(string1); in particularly ASCII.GetBytes(string1) ...
10
by: Christopher H. Laco | last post by:
Long story longer. I need to get web user input into a backend system that a) only grocks single byte encoding, b) expectes the data transer to be 1 bytes = 1 character, and c) uses the HP Roman-6...
4
by: Martin Fletcher | last post by:
when I execute dim strTEMP_DATA as string strTEMP_DATA = Encoding.ASCII.GetString(rBuffer).ToString I alway get a string without the closing quote. I see this in the 'Autos' window, I also...
6
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
3
by: devgrt | last post by:
C#: I have a buffer that is populated with char data from a DLL: byte ret = new byte; I want to convert to a C# string: string msg = Encoding.ASCII.GetString(ret, 0, ret.Length); The problem...
4
by: A_StClaire_ | last post by:
hi, I am using the following code to download multiple file types from a server. .txt files transfer fine. however Word .doc files come through garbled and I don't know enough about encoding...
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
3
by: mazdotnet | last post by:
Hi guys, I'm integrating our systems into another system which returns a response code after doing a POST Byte responseData = objWebClient.UploadValues(postTo, objFormPost); string retVal =...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.