×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Does STRTOFILE() actually create an ASCII file?
2

Does STRTOFILE() actually create an ASCII file?

Does STRTOFILE() actually create an ASCII file?

(OP)
Hi Team!

I have to create an ASCII file (as the person who needs the file said) with values from 5-6 columns. Each column is TAB separated. I used the STRTOFILE() function to write the values with TAB character in between to a file (without the .TXT extension). The file gets created smoothly and we can see that the values are appearing in the proper format and all columns are properly in alignment when we compare it with a sample file provided to us.

But, does the file created by STRTOFILE() conforms to the so called format 'ASCII'?

I searched and came across many write-ups but were not able to come to a conclusion!

Thanks in advance
Rajesh

RE: Does STRTOFILE() actually create an ASCII file?

In short: Halfways yes, as whatever strings you write in STRTOFILE commands in your source code as the 1st parameter are ANSI Codepage, that is what is written as bytes 1:1 into the file.

But there is no such thing as a UTF-8 or ASCII or Unicode file. Only Microsofts Notepad makes a codepage distinction with a so-called BOM, the first 2 or three bytes determine what Notepad uses as codepage(encoding of the file. But this is specific to notepad.exe only. If you use Notepad++ (not from MS) it'll show what BOM it detects and you can use an encoding without BOM.

STRTOFILE() allows you to create a file with a specific BOM, but you should not do so.

Whatever you write as bytes into the file is written, if you don't use string literals but CHR(x) the byte value x is written, whatever is later reading the file is getting these bytes, so no matter what Foxpro displays for CHR(128) in the ASCII table that is Ç, while in European ANSI this is the € Euro currency symbol, if you limit your output to the range CHR(0) to CHR(127) you get normal ASCII output. You get 1:1 the bytes you specify in the first parameter via a VFP string, therefore STRTOFILE in conjunction with FILETOSTR() can even copy binary files, as VFPs string type is not codepage specific either, only its displays. The string type in VFP is also a structure with Length and Bytes-Array, not like C strings 0 terminated, which makes it impossible to have CHR(0) in a C string. But in C++ like in VFP ANSI is the norm for Strings. in C# and other languages that codepage is UTF-16 by the way, and is also neither a file property not some bytes at the start of a c# source code file, it's just convention.

Using VFP in India has other defaults for ANSI than in Europe or US, so when you write some Indian characters in code this is what you also get back displayed, notepad will also show it that way as a file without a BOM is interpreted as ANSI, if you want to look at the content as ASCII you'd need to use a specific editor enabling to set display of content to ASCII.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Does STRTOFILE() actually create an ASCII file?

Rajesh,

You say that the person who needs the file requires it to be ASCII. In that context, it's safe to assume that your file is indeed ASCII.

Strictly speaking, the term ASCII refers to the specific character set used in a string of text. But most people use the term to mean simply any plain text as opposed to binary data. In other words, if you can read the text in a text editor, then the text is ASCII.

So, although your file might or might not technically contain ASCII text, in this case you are safe to assume that it meets your colleague's requirements.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Does STRTOFILE() actually create an ASCII file?

(OP)
Dear Olaf & Mike,

Olaf, thanks for that elaborated explanation. In fact, I learned many things. Your posts are always like sitting in a pin-drop silent classroom listening to those serious lectures!!! (By the way, I am serious)

Mike, as usual, damn simple and straight! May be I wrote my question looking at your answer??!!!

Now, the values/characters we write to the text files are only
Alphabets, Digits, <TAB> character, Hyphen ("-") and period (".").
So, as both of you said, the file I am creating, in all meanings whatever my colleague refers,
IS an ASCII file.

Thanks,
Rajesh

RE: Does STRTOFILE() actually create an ASCII file?

If you mean the 26 letter Latin alphabet, sure.

If your colleague picks on the fact notepad (and notepad++) talk of ANSI encoding, I don't even know an editor verifying strictly for ASCII, but if there are problems with single characters you can surely address that.

Aa Mike said the term ASCII also is often used to refer to plain text files and that means ANSI on Windows, UTF-8 mostly everywhere else and also UTF-8 first 128 characters are ASCII.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close