Coverting text files with binary file page code functionality

Discussion in 'Code Samples & Tips' started by kolbe, Jun 20, 2008.

  1. kolbe

    kolbe Active Member Licensed User

    Hello all,

    I needed to use an a 8-bit ascii (as in with diacritics, accents and the like) file with bassic4ppc so I had to figure out how to use the page code options in the binaryfile object. Don't know if this is the best way to do this but it works. There is not much of an explanation in the help files so thought this might be helpful to someone else.

    tbin1 is the binfile object

    To import a file:

    'convert extended ascii to native utf-8
       FileOpen(c1,"ascii file.txt",cRandom)
    "utf8 file.txt",cWrite)
    'use  1252 or 28591 for the ascii page code
    'read bytes
       length=FileSize("ascii file.txt")
    Dim temp_array(length) As byte

    'convert to string
    'write string to a utf8 file

    To export a file:

    'convert from native utf-8 to extended ascii
       FileOpen(c1,"ascii file.txt",cRandom)
    "utf8 file.txt",cRead)
    'set page code to 1252 or 28591

    'get string from utf8 file

    'convert string to bytes
    Dim temp_array(length) As byte

    'write bytes to ascii file

    use page code 1200 if you need to convert to/from utf16

  2. agraham

    agraham Expert Licensed User

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice