Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 702821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:45:47+00:00 2026-05-14T03:45:47+00:00

I am being sent text files saved in ISO 88591-1 format that contain accented

  • 0

I am being sent text files saved in ISO 88591-1 format that contain accented characters from the Latin-1 range (as well as normal ASCII a-z, etc.). How do I convert these files to UTF-8 using C# so that the single-byte accented characters in ISO 8859-1 become valid UTF-8 characters?

I have tried to use a StreamReader with ASCIIEncoding, and then converting the ASCII string to UTF-8 by instantiating encoding ascii and encoding utf8 and then using Encoding.Convert(ascii, utf8, ascii.GetBytes( asciiString) ) — but the accented characters are being rendered as question marks.

What step am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:45:48+00:00Added an answer on May 14, 2026 at 3:45 am

    You need to get the proper Encoding object. ASCII is just as it’s named: ASCII, meaning that it only supports 7-bit ASCII characters. If what you want to do is convert files, then this is likely easier than dealing with the byte arrays directly.

    using (System.IO.StreamReader reader = new System.IO.StreamReader(fileName,
                                           Encoding.GetEncoding("iso-8859-1")))
    {
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter(
                                               outFileName, Encoding.UTF8))
        {
            writer.Write(reader.ReadToEnd());
        }
    }
    

    However, if you want to have the byte arrays yourself, it’s easy enough to do with Encoding.Convert.

    byte[] converted = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), 
        Encoding.UTF8, data);
    

    It’s important to note here, however, that if you want to go down this road then you should not use an encoding-based string reader like StreamReader for your file IO. FileStream would be better suited, as it will read the actual bytes of the files.

    In the interest of fully exploring the issue, something like this would work:

    using (System.IO.FileStream input = new System.IO.FileStream(fileName,
                                        System.IO.FileMode.Open, 
                                        System.IO.FileAccess.Read))
    {
        byte[] buffer = new byte[input.Length];
    
        int readLength = 0;
    
        while (readLength < buffer.Length) 
            readLength += input.Read(buffer, readLength, buffer.Length - readLength);
    
        byte[] converted = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), 
                           Encoding.UTF8, buffer);
    
        using (System.IO.FileStream output = new System.IO.FileStream(outFileName,
                                             System.IO.FileMode.Create, 
                                             System.IO.FileAccess.Write))
        {
            output.Write(converted, 0, converted.Length);
        }
    }
    

    In this example, the buffer variable gets filled with the actual data in the file as a byte[], so no conversion is done. Encoding.Convert specifies a source and destination encoding, then stores the converted bytes in the variable named…converted. This is then written to the output file directly.

    Like I said, the first option using StreamReader and StreamWriter will be much simpler if this is all you’re doing, but the latter example should give you more of a hint as to what’s actually going on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Text gets accumulates piecemeal before being sent to client. Now we use own class
I need to validate a basic authorization header that is being sent to my
I'm using a Socket to communicate with a ServerSocket. Strings are being sent from
I have an HTML input form that is being sent as a PHP_SELF and
I've got data being sent from a client side which is sending it like
The following $header is being sent via PHP's mail($to,$subject,$content,$header) command. The mail arrives and
How can I watch the messages being sent back and for on urllib shttp
I've got 2 signals being sent at user registration, socialauth_registered and post_save. I'd like
I am trying to use zlib for compressing data being sent to a client.
Setting up email details in web.config - but no email is being sent! <appSettings>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.