Problem with FindStr()

Find quick help here to get you started with Hollywood
papiosaur
Posts: 192
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem with FindStr()

Post 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...
User avatar
jPV
Posts: 626
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Problem with FindStr()

Post 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.
User avatar
jPV
Posts: 626
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Problem with FindStr()

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

Re: Problem with FindStr()

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

Re: Problem with FindStr()

Post by papiosaur »

@jPV: thanks for your explanations! i will test.

@fink: sorry, same error "Invalid UTF-8 string in argument1!"
Flinx
Posts: 227
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: Problem with FindStr()

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

Re: Problem with FindStr()

Post by papiosaur »

@Flinx: it's the same file, sorry i have changed the name.
Post Reply