Lower ASCII Text file opens as Unicode in Notepad

Piglette
Lounger
Posts: 35
Joined: 20 Feb 2010, 05:05

Lower ASCII Text file opens as Unicode in Notepad

Post by Piglette »

This started out as a programming issue (AutoHotkey vs VBS output - see my 2/9 Piglette posting on the AHK Forum), but has really resolved to a font question:

1) Copy this single-line string to the Clipboard (ending at the 999 - no newline):

BAMS MID DBA_NAME Pricing method 341 340 20B 30D 372 322 472 564 563 273 549 553 274 527 528 6AC 10D 10A 10J 10P 18E 10E 10B 10K 10Q 800 801 810 811 820 821 660 661 850 851 870 871 999

and paste into Notepad.

Save the text file, close Notepad and open the saved file. So far so good

---

2) Now copy this single-line string to the Clipboard (ending at the 999 - no newline):

BAMS MID DBA_NAME Pricing Method 341 340 20B 30D 372 322 472 564 563 273 549 553 274 527 528 6AC 10D 10A 10J 10P 18E 10E 10B 10K 10Q 800 801 810 811 820 821 660 661 850 851 870 871 999

and paste into Notepad.

Save the text file, close Notepad and open the saved file. Shock!

Files 1 and 2 are byte-for-byte the same, except that I have changed "method" to "Method"

Can anyone explain this?

Thanks

Lukas

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by HansV »

Sorry, I don't get it - this is what I see in Windows 7 ("Kladblok" is the Dutch name of Notepad):
x506.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

Piglette
Lounger
Posts: 35
Joined: 20 Feb 2010, 05:05

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by Piglette »

Hans:

Thanks for getting back to me. In XP Pro/Home and Vista the results are very different. The following png's are from XP Pro:
A.png
B.png
In A,
1.txt is what we get with "m"
2.txt is what we get with "M"
3.txt - I have just hit the Enter key and saved (see below)

In B, we have what the file viewer sees. Note that 1 and 2 are identical except for the m/M byte
In 3 we see leading FF FE bytes, and the file ends with 0D 00 0A 00

In Vista, Notepad displays very dramatic Japanese Kanji. The screen shot turned to boring rectangles when I e-mailed it to this XP machine.

Any thoughts?

Thanks

Lukas
You do not have the required permissions to view the files attached to this post.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by jscher2000 »

In Win XP Pro, I have four choices of encoding. ASCII is not one of them. Do any of these behave strangely for you?
WinXPPro-Notepad-Encodings.zip
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by HansV »

In Windows 7, all 8 files from your zip file look exactly the same in Notepad (except for the m/M of course).
Best wishes,
Hans

Piglette
Lounger
Posts: 35
Joined: 20 Feb 2010, 05:05

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by Piglette »

Thanks Hans:

We also find that copy/paste to another file works fine. And the "bad" text prints fine.

A buddy kindly wrote the following and ran the compiled C++ code:

#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string strTestCode = "BAMS MID DBA_NAME Pricing Method 341 340 20B 30D 372 322 472 564 563 273 549 553 274 527 528 6AC 10D 10A 10J 10P 18E 10E 10B 10K 10Q 800 801 810 811 820 821 660 661 850 851 870 871 999";
string strTestCode2 = "BAMS MID DBA_NAME Pricing method 341 340 20B 30D 372 322 472 564 563 273 549 553 274 527 528 6AC 10D 10A 10J 10P 18E 10E 10B 10K 10Q 800 801 810 811 820 821 660 661 850 851 870 871 999";

ofstream Otput;
Otput.open("Output.txt");
Otput << strTestCode ;
Otput.close();
Otput.open("Output2.txt");
Otput << strTestCode2 ;
Otput.close();
return 0;
}

Both files display fine

So we can now say that the problem must lie with the (US) Windows API

I don't feel like opening a case with Microsoft, so we can let it rest..

Thanks again

Lukas

Piglette
Lounger
Posts: 35
Joined: 20 Feb 2010, 05:05

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by Piglette »

Works fine in US Windows 7. So whatever it was, it's fixed.

Thanks

Lukas

Piglette
Lounger
Posts: 35
Joined: 20 Feb 2010, 05:05

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by Piglette »

Interesting!

http://blogs.msdn.com/b/michkap/archive ... 31016.aspx" onclick="window.open(this.href);return false;

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Lower ASCII Text file opens as Unicode in Notepad

Post by HansV »

Apparently, Microsoft has fixed this kind of bug in Windows 7 - the example Michael Kaplan gives doesn't work there, the file opens normally, not with boxes or Chinese characters.
Best wishes,
Hans