Problem with lines feed into a texteditor box

Discuss GUI programming with the RapaGUI plugin here
Post Reply
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Problem with lines feed into a texteditor box

Post 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?
User avatar
Redlion
Posts: 111
Joined: Sun Jul 10, 2011 5:05 am
Location: Perth, Western Australia

Re: Problem with lines feed into a texteditor box

Post 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
----------------------------------------------------------------------------------------
Redlion
Sam460 Lite
A4000 A3000 A2000 A1200 A1000 A600 A500 CD32
plouf
Posts: 586
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Problem with lines feed into a texteditor box

Post 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?
Christos
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with lines feed into a texteditor box

Post by papiosaur »

Thanks for your answers !

I will search this special double string and remove which one cause trouble.
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with lines feed into a texteditor box

Post 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
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with lines feed into a texteditor box

Post by papiosaur »

@plouf: this is the file with CRLF

https://www.morphos-storage.net/upload/dev/ball.cpp
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with lines feed into a texteditor box

Post 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$)
Flinx
Posts: 261
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Problem with lines feed into a texteditor box

Post 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)
papiosaur
Posts: 213
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with lines feed into a texteditor box

Post by papiosaur »

Thanks a lot Flinx!!!!!

Work better ;-)
Post Reply