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

x
?
Solved

Storing ASCII charactors greater than 127 as a one byte string in .NET

Posted on 2016-09-12
5
Medium Priority
?
48 Views
Last Modified: 2016-10-02
Working with a .NET web page that needs to write data retrieved from a data base to a local file where numbers are converted to a two byte string and then written to a file.  Basically the old MKI$ function.  Seems like any number higher than 127 will be written out as a two byte string due to the way high ASCII numbers are handled now.  Is there any function or string definition that will still handle high ASCII number up to 255 and let the one byte string be written to a file?  Thanks very much for any help.
0
Comment
Question by:Member_2_6470879
[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
5 Comments
 
LVL 46

Expert Comment

by:aikimark
ID: 41795798
What do/should your inputs and outputs look like?
0
 
LVL 35

Expert Comment

by:ste5an
ID: 41795810
What encoding (code page) to you need for your file? See also Encoding. And use it with StreamWriter Constructor (Stream, Encoding).
0
 
LVL 35

Expert Comment

by:sarabande
ID: 41796033
Seems like any number higher than 127 will be written out as a two byte string due to the way high ASCII numbers are handled now.  

that is not true. double-byte strings are called UNICODE by MS (and actually is UTF16 encoding what is only the first layer of full 32-bit Unicode) and contain character codes up to 65535 (256x256 - 1).

one-byte strings normally (in US and most Europe countries) use ANSI codepage (codes 0 to 255). the ANSI codepage contains  ASCII as the first half of the code page.

in .NET all strings were handled as double-byte strings. that also includes strings with ASCII (7-bit character codes) texts and ANSI texts (8-bit character codes). if you look at the strings with a hex editor, you see that the high byte of each double-byte character is 0. so conversion of MS UNICODE strings to one-byte strings is easy: take-over any second byte to a byte array or cast each double-byte character to one byte char. there are appropriate functions for both conversions available.

Sara
0
 
LVL 1

Accepted Solution

by:
Member_2_6470879 earned 2000 total points (awarded by participants)
ID: 41796746
Thanks everyone.  Adding Encoding.Default to the StreamWriter Constructor method worked.  I missed the fact that the Default would actually do anything so didn't try that.  But it is exactly what I needed to specify.  Now the two byte string for 128 for instance is stored as hex 80 00 in the disk file rather than the three byte string I was getting before.
0
 
LVL 35

Expert Comment

by:sarabande
ID: 41825219
Actually the Asker found a working solution themselves. None of the comments added by Experts - including the one I added myself - could claim for assistance without doubts.

Sara
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

705 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