[Gambas-user] Class to Read/Write INI files

me nospam at ...789...
Wed Jan 12 11:43:30 CET 2005


Frank Berg wrote:
> hi,
> i was try to make a new class for edit ini files,

> call_from = -

What on earth is that?

> an real text file has none formatting information?!

I understand what you are getting at, but without some code to look at, it's
almost impossible to know for sure what you think the problem is. Next time,
please include some code, as well as sample input and output.

Because you are getting \r appearing in your string, I conclude that you
must have a DOS file with lines that are terminated using CRLF pairs.

Unix file systems behave differently to DOS/Windows. In DOS, text files
contain embeded control characters to mark the EOL, usually a CR LF pair. In
Unix, they are marked with \n, which is not returned by gambas when you read
a file.

You have to convert the DOS file to Unix format, or your code must make
adjustments for the differences in the format as it reads the file.

If you do not need to preserve the DOS file format, you can read the entire
stream and break the lines in memory at each \r\n then rewrite the whole
file without the CRLF pair.

If you need to preserve the format, you could try using the INPUT keyword to
loop through the file, reading each word until you get nothing back, where a
word is some text terminated by a space, CR, LF or CRLF. Getting an empty
string should indicate that you have hit a control character. Reading past
the empty values should take you to the first word of the next line, so on
and so forth, until you hit the EOF.

> i was try to make a new class for edit ini files

Your real problem is not just reading the DOS file. You are going to have
problems writing the DOS file. You will have to read the file into memory in
its entirety, make whatever changes need to be made, then you will have to
construct the entire output in memory as one big string and write the string
out as a binary.





More information about the User mailing list