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 9246677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:32:52+00:00 2026-06-18T09:32:52+00:00

I have a textfile with the content: A B C D Ä 1 4

  • 0

I have a textfile with the content:

A B C D Ä 1 4 0 $ % & € / [ ) = ß ² µ §

If you ask me about the encoding – I have no idea. If I open it with Notepad++ I see in the encoding menu Encoding in ANSI

I would like to read this file, and recognize every character correctly. As code I have this:

//open and locking the file
using (FileStream fs = File.Open(@"C:\testfile.txt", FileMode.Open, FileAccess.Read, FileShare.None))
{
    using (TextReader reader = new StreamReader(fs))
    {
        string line;
        //reading and printing each line
        while ((line = reader.ReadLine()) != null)
        {
            System.Console.WriteLine(line);
        }
    }
}

As output I get:
enter image description here

So for Ä € ß ² µ § I get a ?. That why I thought It’s because of the console, so changed it to UTF8, so I’m maybe able to get a better output. But its not really helping.

System.Console.OutputEncoding = System.Text.Encoding.UTF8;

enter image description here

Thats why I think there is something wrong while reading the file. I should probably change the encoding of the StreamReader. But there are not that many options. I was trying UTF8, ASCII, but it’s not helping. Any ideas?

Edit: Thanks Matthew, adding System.Text.Encoding.Default to the StreamReader is helping. Now only the char € is not recognizable. Don’t get it, are some chars “special”?

Edit2: alright, the € was only a problem because the console is buggy(?). If I look at the string in the debug mode, the € is also fine.

So the working solution for me is now:

1.) Using the reader with default encoding:

using (TextReader reader = new StreamReader(fs, System.Text.Encoding.Default))

AND

2.) Not using the console for output, just reading the string in debug mode

  • 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-06-18T09:32:53+00:00Added an answer on June 18, 2026 at 9:32 am

    If you are using ANSI, you can do it like this:

    using (TextReader reader = new StreamReader(fs, System.Text.Encoding.Default))
    

    However, that will only work if your current code page is correct for the file that you are reading. It probably will be, but for full portability you should determine the actual code page that you’re using and use:

    using (TextReader reader = new StreamReader(fs, new System.Text.Encoding(codePageNumber)))
    

    where codePageNumber is the code page of the text file.

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

Sidebar

Related Questions

If I have a a textfile say file.txt and it contains random words like:
I am trying to read the content of a text-file, but have no idea
I have an XML spec that looks like this: <Root> <Directory Name=SomeName> <TextFile Name=ExampleDocument.txt>This
I have a description text file with content constructed in such manner: Book title
okay, so i have a text file with example content below line1with some random
I have a dynamic text file that picks content from a database according to
I have a textfile consisting of lines as follows: 12,538123,724026,8.01 12,538123,724026,8.5 12,538123,724026,8.91 34,538123,724026,8.01 34,538123,724026,8.5
I have a textfile and on each line is a single word followed by
I've got a problem I can't find any solution for. I have a textfile
I have a large textfile, which has linebreaks at column 80 due to console

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.