Page 1 of 1

Problem with lines feed into a texteditor box

Posted: Sat Sep 28, 2024 10:08 pm
by papiosaur
Hello,

i show contents of files into a Texteditor box (read only and font style fixed) but i have lines feed between each lines there is no in another file editor like FlowStudio on MorphOS.

If i save the file with FlowStudio (in UTF8 format), the line feed disappears in the Texteditor box after reload it.

i have tried to use ConvertStr from ISO885981 to UTF-8 but without success.

Any ideas please?

Re: Problem with lines feed into a texteditor box

Posted: Sun Sep 29, 2024 4:00 am
by Redlion
@ Papiosaur

If you read the the Texteditor section of the manual it explains that window adds a line feed and carriage return at the end of a line. Just about everything else does not.

A quick and dirty way is to load the file in as a string and then replace all the line feed and carriage returns with just a carriage return and then place it in the Editor.

In the Editor I wrote I made a function to remove every second line if it was blank.

Hope that helps

Leo

Re: Problem with lines feed into a texteditor box

Posted: Sun Sep 29, 2024 9:10 am
by plouf
This probably has to do with the fact of windows cr-lf vs other oses only lf

Do you have a sample "problematic" file?

Re: Problem with lines feed into a texteditor box

Posted: Sun Sep 29, 2024 11:00 am
by papiosaur
Thanks for your answers !

I will search this special double string and remove which one cause trouble.

Re: Problem with lines feed into a texteditor box

Posted: Sun Sep 29, 2024 10:54 pm
by papiosaur
I have tried to replace Chr(13) .. Chr(10) by only Chr(13) but without success...

@plouf: i give you a link of the file tomorrow

Re: Problem with lines feed into a texteditor box

Posted: Mon Sep 30, 2024 9:28 am
by papiosaur
@plouf: this is the file with CRLF

https://www.morphos-storage.net/upload/dev/ball.cpp

Re: Problem with lines feed into a texteditor box

Posted: Mon Sep 30, 2024 10:14 am
by papiosaur
This my part of code:

Code: Select all

text$ = filetostring("ram:ball.cpp")
n = countstr(text$, Chr(13) .. Chr(10), True, 0, #ENCODING_RAW)
consoleprint(n)
pos = 0
posi$ = 1
For i = 0 to n
	pos = findstr(text$, Chr(13) .. Chr(10), True, pos, #ENCODING_RAW)
	consoleprint(posi$ .. ". " ..pos)
        replacestr(text$, Chr(13) .. Chr(10), Chr(13), True, pos, #ENCODING_RAW)
	posi$ = posi$ +1
	pos = pos +1
Next
moai.Set("log", "text", text$)

Re: Problem with lines feed into a texteditor box

Posted: Mon Sep 30, 2024 11:46 am
by Flinx
Two mistakes:
The loop should be run until n-1, and ReplaceStr() does not change the given string but returns the result.
But you do not need the loop. One line is enough.

Code: Select all

text$= ReplaceStr(text$, "\r\n", "\n", True, 0, #ENCODING_RAW)

Re: Problem with lines feed into a texteditor box

Posted: Mon Sep 30, 2024 12:06 pm
by papiosaur
Thanks a lot Flinx!!!!!

Work better ;-)