Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# 1byte-1char strings

C# 1byte-1char strings

Scheduled Pinned Locked Moved C#
csharpdelphibeta-testingjson
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Shaw
    wrote on last edited by
    #1

    Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#. I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char. I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK. Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string? P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.:-O Thanx! Dave Shaw History admires the wise, but elevates the brave. - Edmund Morris

    L D U D 4 Replies Last reply
    0
    • D Dave Shaw

      Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#. I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char. I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK. Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string? P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.:-O Thanx! Dave Shaw History admires the wise, but elevates the brave. - Edmund Morris

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Dave Shaw wrote:

      The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char.

      :doh: thats 2 bytes rather... Use System.Text.Encoding.UTF8.GetBytes() . xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!

      1 Reply Last reply
      0
      • D Dave Shaw

        Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#. I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char. I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK. Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string? P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.:-O Thanx! Dave Shaw History admires the wise, but elevates the brave. - Edmund Morris

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Leppie is right, Unicode is 2-bytes, not 8. Unicode makes room for 65,535 characters in a set (255 * 255). 8 Bytes would allow lots and lots and lots of characters, like (255 ^ 8). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        L 1 Reply Last reply
        0
        • D Dave Shaw

          Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#. I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char. I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK. Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string? P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.:-O Thanx! Dave Shaw History admires the wise, but elevates the brave. - Edmund Morris

          U Offline
          U Offline
          uno freeware
          wrote on last edited by
          #4

          well you can always use byte vectors, or pointers to byte in an unsafe part of the code... then you can use normal io.streamwriter for writing and io.streamreader for reading <- true inside to understand outside ->

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            Leppie is right, Unicode is 2-bytes, not 8. Unicode makes room for 65,535 characters in a set (255 * 255). 8 Bytes would allow lots and lots and lots of characters, like (255 ^ 8). RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            L Offline
            L Offline
            lmoelleb
            wrote on last edited by
            #5

            Unicode makes room for something like a million characters. Unicode does not take up any "bytes". It just define which "character" is at which number. In order to represent Unicode in memory or on file, you need an encoding of the Unicode character set. The UTF-16 encoding (which is probably what you refer to as this is what C# use internally) will use 2 or 4 bytes per character.

            1 Reply Last reply
            0
            • D Dave Shaw

              Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#. I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char. I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK. Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string? P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.:-O Thanx! Dave Shaw History admires the wise, but elevates the brave. - Edmund Morris

              D Offline
              D Offline
              Daniel Turini
              wrote on last edited by
              #6

              Probably this MSDN article[^] will solve your problem. Just specify CharSet = Auto. I don't see dead pixels anymore... Yes, even I am blogging now!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups