Page 2 of 2

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 8:40 am
by papiosaur
Hi jPV,

Bizarre work for you...

Same problem with FindStr() here:

Code: Select all

text$ = filetostring("ram:toto.txt")
pos$ = FindStr(text$, Chr(27))
consoleprint(pos$)
The code doesn't work...

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 9:20 am
by jPV
You must have some non-English alphabets in your toto.txt file... because the original ESC.txt file you gave didn't have any of those and does work. So, I'm guessing it's about having non-UTF8 characters in your input file, but you're running Hollywood in UTF8 mode (the default nowadays).

You could run your whole Hollywood app in non-UTF8 mode (SetDefaultEncoding() or @OPTIONS), or define the character encoding in functions when needed (read more about encodings).

This would probably work when just defining the encoding in a function:

Code: Select all

text$ = FileToString("ram:toto.txt")
pos$ = FindStr(text$, Chr(27), True, 0, #ENCODING_RAW)
consoleprint(pos$)
BTW. if you want to get rid of the whole escape sequence (Amiga escape sequences explained here), you could use, for example, PatternReplaceStr() like this:

Code: Select all

text$ = FileToString("ram:toto.txt")
s$ = PatternReplaceStr(text$, "\27%[%d*%a", "")
StringToFile(s$, "ram:toto2.txt")
To explain the pattern:
"\27" is the code point value for the escape character
"%[" matches the "[" character
"%d*" matches 0 or more occurences of digits, d tells it's a digit and * tells the amount of them
"%a" matches any single letter
So, if there's a character combination matching all these rules, it will be removed. In this way you get rid of start and end markers for escape sequences in one go.

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 10:06 am
by jPV
And one another option would of course be to convert the input data to UTF8 if needed:

Code: Select all

text$ = FileToString("ram:toto.txt")
If Not ValidateStr(text$) Then text$ = ConvertStr(text$, #ENCODING_AMIGA, #ENCODING_UTF8)
pos$ = FindStr(text$, Chr(27))
consoleprint(pos$)

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 10:12 am
by Flinx
papiosaur wrote: Mon Aug 12, 2024 8:40 am The code doesn't work...
Please explain in which way it doesn't work. Error messages? Output? Program freeze? Satanic voices in your computer?
For me the code works too, and you get better help if you tell exactly what happens.

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 10:19 am
by papiosaur
@jPV: thanks for your explanations! i will test.

@fink: sorry, same error "Invalid UTF-8 string in argument1!"

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 10:27 am
by Flinx
papiosaur wrote: Mon Aug 12, 2024 10:19 am @fink: sorry, same error "Invalid UTF-8 string in argument1!"
Then could you please upload the toto.txt too? Or is that your ESC.txt?

Re: Problem with FindStr()

Posted: Mon Aug 12, 2024 11:00 am
by papiosaur
@Flinx: it's the same file, sorry i have changed the name.