Problem with FindStr()
Problem with FindStr()
Hello,
i would like to search a substring in a string (a file converted into a string with filetostring command) with FindStr() but i have this error message:
Invalid UTF-8 string in argument1! There are some 'ESC' special caracters in the string...
Possibilty to resolve this problem please?
i would like to search a substring in a string (a file converted into a string with filetostring command) with FindStr() but i have this error message:
Invalid UTF-8 string in argument1! There are some 'ESC' special caracters in the string...
Possibilty to resolve this problem please?
Re: Problem with FindStr()
Is there a special command to remove all control caracters from a string?
I see IsCntrl() command but seems don't work...
I see IsCntrl() command but seems don't work...
Re: Problem with FindStr()
yes it works here is an example to detect if there is a control character (character 10 = Line Feed)
and removing it
p.s. What os ? AmiaOSes have some limitation in UTF
and removing it
Code: Select all
str$ = "123"..Chr(10).."567"
DebugPrint(str$)
DebugPrint("Is Control char in position ? = "..IsCntrl(str$,3))
str$ = ReplaceStr(str$,Chr(10),"")
DebugPrint(str$)
Christos
Re: Problem with FindStr()
Thanks plouf for your answer!
Bizarely
newstr$=ReplaceStr(str$,Chr(27),"") don't work...
newstr$=patternreplaceStr(str$,Chr(27),"") work...
i'm on MorphOS
Bizarely
newstr$=ReplaceStr(str$,Chr(27),"") don't work...
newstr$=patternreplaceStr(str$,Chr(27),"") work...
i'm on MorphOS
Re: Problem with FindStr()
can you provide a non working example ?
this one works in windwos 10 and morphos 3.18
message says length = 6
Ps also in chr27
this one works in windwos 10 and morphos 3.18
message says length = 6
Code: Select all
str$ = "123"..Chr(7).."567"
DebugPrint(str$)
DebugPrint("Is Control char in position ? = "..IsCntrl(str$,3))
str$ = ReplaceStr(str$,Chr(7),"")
SystemRequest("length "..StrStr(StrLen(str$)),"of this String > ".. str$,"OK")
Christos
Re: Problem with FindStr()
Sorry, i have no example but you can try with my file to remove Chr(27) with ReplaceStr() to see if it work at your home:
https://www.morphos-storage.net/upload/dev/ESC.txt
https://www.morphos-storage.net/upload/dev/ESC.txt
Re: Problem with FindStr()
i suspect wrong usage of ReplaceStr(), thats why a example always help..
here is a example that tested and works in windows and morphos
NOTE that ReplaceStr() search ALL string and replace not in current position only
here is a example that tested and works in windows and morphos
NOTE that ReplaceStr() search ALL string and replace not in current position only
Code: Select all
str$ =FileToString("f:\\ESC.txt")
len = StrLen(str$)-1
DebugPrint("before "..FindStr(str$,Chr(27)))
For i=0 To 32
str$ = ReplaceStr(str$,Chr(i),"")
Next
DebugPrint("After "..FindStr(str$,Chr(27)))
SystemRequest("original = "..StrStr(len).. " after "..StrStr(StrLen(str$)),str$,"OK")
Christos
Re: Problem with FindStr()
Hmm.. I don't seem to have a problem with that ESC.txt and FindStr... would be nice to get a minimal example code where it fails. Now it sounds that you are fixing something that really isn't broken. And in any case there's always a way to read data without modifying it.
Re: Problem with FindStr()
Hello,
thank plouf for your code, i will test it on MorphOS.
This is my simple code doesn't work:
thank plouf for your code, i will test it on MorphOS.
This is my simple code doesn't work:
Code: Select all
text$ = filetostring("ram:toto.txt")
s$ = ReplaceStr(text$, Chr(27), "")
stringtofile(s$, "ram:toto2.txt")
Re: Problem with FindStr()
For me it looks to work. When using the ESC.txt file the toto2.txt file is 10 bytes smaller than the original. And in the original there are 10 escape characters that have been removed from the result. All OK as supposed to be.papiosaur wrote: ↑Mon Aug 12, 2024 8:03 am This is my simple code doesn't work:
Code: Select all
text$ = filetostring("ram:toto.txt") s$ = ReplaceStr(text$, Chr(27), "") stringtofile(s$, "ram:toto2.txt")
But how is this related to the original question about FindStr() and UTF-8 error, a work-around? How to reproduce the original issue to get that solved first?