473,804 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(byteA rray)
(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:13162055 440
_/ Email:Ni***@xom i.cn ,co****@163.com
_/
_/ Profession & Focus
_/ High precision semiconductor metrology system vendor.
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Jun 19 '06 #1
4 14325
Encoding.ASCII. GetString(byteA rray, 0, Array.IndexOf(b yteArray, (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(byteA rray)
(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(byteA rray)
(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:13162055 440
_/ Email:Ni***@xom i.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**********@g mail.com>
??????:11****** *************** @h76g2000cwa.go oglegroups.com. ..
Encoding.ASCII. GetString(byteA rray, 0, Array.IndexOf(b yteArray, (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(byteA rray)
(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
3422
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) Encoding1.GetChars(string1); Encoding1.GetChars(arrayofbytes1);
10
687
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 codepage system wide. As much as it sounds good, UTF/Unicode encoding is not an option, nor is changing the codepage. Tackling the first is easy via Encoding.Default.GetBytes and shoving it over the network. However, Encoding.Default is the...
4
1533
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 see it when I hoover my mouse over the strTEMP_DATA above. An example would be: It looks like "test
6
1487
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 into problems. Sending code: ASCIIEncoding encoding = new ASCIIEncoding(); string lcUrl = "http://localhost/test/receive.aspx"; HttpWebRequest loHttp =
3
6059
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 is I never know in advance what size the string will be. When I call Encoding.ASCII.GetString I need to specify the size. If I set it to ret.Length as above then in the debugger I can see msg is the full 1024 bytes (0 padded at the end...
4
2043
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 to understand why. the object 's' is a Mentalis.org component that, for all purposes here, is a System.Net.Socket. the line I commented out is one that hard-codes the encoding to 'ASCII' which I assume would only hurt me.
0
3635
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 value (which varies depending on the data being written), characters not available in the encoding specified in the Encoding property of the XmlWritterSettings instance used to create the XmlWriter are being written to the resulting XML document as...
9
4150
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. What am I doing wrong? Dim plainText As String plainText = "tâ•e" Dim plainTextBytes() As Byte Dim enc As Encoding = Encoding.ASCII plainTextBytes = enc.GetBytes(plainText)
3
1643
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 = Encoding.ASCII.GetString(responseData); The retVal looks like
0
10318
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9132
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.