Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Byte array loses data when converted to ascii string

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    Resolved [RESOLVED] [2005] Byte array loses data when converted to ascii string

    I'm writing a piece of software that will print barcodes using a font. (My method of manually drawing the barcode didn't yield the results I was looking for and I'm on a deadline.) So now I'm using a font. Unfortunatly, because it's code 128 (types b and c, intermixed) I have to pre-encode the strings, calculate a checksum, etc. No big problem.

    Because code 128 only has 156 different symbols, the font is ASCII (i.e. it uses character codes from 0 to 255 and is only 1 byte per character.) It should be noted that several of these symbols are control codes and must be displayed correctly for the barcode to work at all.

    The encoding I'm doing works with a byte array to make individual changes easier.

    The problem arises when I need to draw the string. I have to convert the byte array to a string first. For some reason, VB likes to replace certain character values with a question mark. This is not some on screen representation of a character that can't be displayed. It's actually substituting one character for another in the variable.

    This should have nothing to do with unicode to ascii and having ascii unable to represent the character.

    vb Code:
    1. Dim bc1Text As String = "+H822023450022406"
    2.             Dim bc1EncodedBytes As Byte() = Encode128(bc1Text)
    3.  
    4.             Dim TextEncoder As New System.Text.ASCIIEncoding
    5.             Dim bc1EncodedText As String = TextEncoder.GetString(bc1EncodedBytes)

    The last line is where the data is changing. bc1EncodedText now has different data than bc1EncodedBytes.

    An example (and I've checked this by converting the resultant string back into a byte array and reading the value) is that bc1EncodedBytes(0) and bc1EncodedBytes(1) have a value of 155 and 150 respectively, but the characters in the string and a byte array made from the string have the values of 63 and 63 respectively.

    Since I know that Ascii can represent characters 155 and 150, even if there's no visual representation, I'm not entirely sure why they are being converted to a question mark.

    Is there any way to prevent it from being converted to a question mark so that I can properly use the control codes in my barcode font?

    This is being used with Graphics.DrawString, so keeping it as a byte array won't work either.
    Last edited by agent; Sep 1st, 2008 at 04:31 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width