[solved] readfile utf8 crlf

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
zakhar
Posts: 172
Joined: 08 Sep 2010 21:13

[solved] readfile utf8 crlf

Post by zakhar »

Hello, Dear XYplorer Community!

Windows 10 Enterprise LTSC German, XYplorer v. 26.00.0300

Using a script I try to rewrite an utf8-encoded (utf8 according Notepad++) txt-file.
1. readfile(txt-file) or readfile(txt-file,"t") or readfile(txt-file,"t_BLU8") <- same results...,
2. some text transformations,
3. building new file content:

Code: Select all

if($file_ctn != ""){$file_ctn = $file_ctn<crlf>$line___n;}
if($file_ctn == ""){$file_ctn = $line___n;}
3. writefile(txt-file,new-file-content,"o","utf8").

The problem is that the empty lines (lines, which content is only a <crlf>) on the start of the txt-file are cut.

What can I do to avoid empty lines cutting?
Last edited by zakhar on 03 Jun 2024 14:33, edited 1 time in total.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: readfile utf8 crlf

Post by highend »

Provide a sample file + the full script?
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 172
Joined: 08 Sep 2010 21:13

Re: readfile utf8 crlf

Post by zakhar »

Here is an example file and the script.
Attachments
0-text.txt
(458 Bytes) Downloaded 36 times
Last edited by zakhar on 04 Jun 2024 16:53, edited 1 time in total.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: readfile utf8 crlf

Post by highend »

Code: Select all

        $j = 1;
        foreach($line____,$file_cto,<crlf>){
            sysdebug "j: " . $j . " = '" . $line____ . "'";
            $j++;

Code: Select all

[6956] j: 1 = ''
[6956] j: 2 = ''
[6956] j: 3 = '12:40 03.06.2024 - Hello, Dear XYplorer Community!'
[6956] j: 4 = '                   Windows 10 Enterprise LTSC German, XYplorer v. 26.00.0300'
[6956] j: 5 = '                   Using a script I try to rewrite an utf8-encoded (utf8 according Notepad++) txt-file.'
[6956] j: 6 = '                   1. readfile(txt-file) or readfile(txt-file,"t") or readfile(txt-file,"t_BLU8") <- same results...,'
[6956] j: 7 = '                   2. some text transformations,'
[6956] j: 8 = '                   3. building new file content:'
[6956] j: 9 = ''
So no, reading the file didn't cut off anything, the code inside that loop block is responsible for what happens
I'd take a look at your else block in there...
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 172
Joined: 08 Sep 2010 21:13

Re: readfile utf8 crlf

Post by zakhar »

I do not know how to change the code

Code: Select all

} else {
       $line___n = $line____;
}
so that the empty lines would not be cut.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: readfile utf8 crlf

Post by highend »

Something like that should work

Code: Select all

Replace:
            if($file_ctn != ""){$file_ctn = $file_ctn.<crlf>.$line___n;}
            if($file_ctn == ""){$file_ctn = $line___n;}

With:
            if($line___n != ""){$file_ctn .= $line___n . <crlf>;}
            else {$file_ctn .= <crlf>;}


And:
            writefile($file____,$file_ctn,"o","utf8");

With:
            writefile($file____,trim($file_ctn,<crlf>,"R"),"o","utf8");
One of my scripts helped you out? Please donate via Paypal

zakhar
Posts: 172
Joined: 08 Sep 2010 21:13

Re: readfile utf8 crlf

Post by zakhar »

highend wrote: 03 Jun 2024 14:07 Something like that should work ...
Indeed!
It works!
Thank you, highend!

Post Reply