ptp
USA
Asked
— Edited
Resolved by DJ Sures!
Tested with the last version and the previous version
The following code:
1: ClearVariables()
2: $test1 = FileReadAll("c:\dev\test.txt")
3: FileReadClose("c:\dev\test.txt")
4: Print(Length($test1))
Generates an error:
Quote:
Error on line 4: Missing String Quotes or Invalid Expression at index 0: "hello
the "hello" is inside the file, not in the code.
Strings in EZ-Robot script can only be one line (I think it is because the compiler reads the code one line at a time with no way of encapsulating it, DJ correct me if I am wrong) , since you are reading all the contents of the file I assume you have multiple lines or returns in it (returns are considered invalid chars in the string). You can get around this by using an array and reading one line at a time in a loop like the code below.
To find the length just add up the length of all the values in the array.
Hope that helps.
@mikebmac:
Thanks for that info, after a few hours struggling i didnt expected to be the expected behavior.
I imagine someone writing you need to do tutorial abc or is a bug.
if is true the string is broken, it will be impossible to parse multi line contents/buffers.
Also does not make sense a function filereadall when you can only do filereadline.
no where is explaining the string only handles a single line.
this time i really think there is a learning tutorial missing: "scripting cookbook / tricks"
ptp, I think I have used this in the past without issue. I will have to check an old project to make sure and will get back to you, but I believe that I had to write an app that removed things like quotes and such to make it work. In the file, does it have a quote after hello?
Checking old project now.
FileReadLine is what I used. I think my app also removed /r/n and replaced it with a space to make one long line.
The original file had multilines, equals, quotes. The one i used for testing has two lines.
This is the same as https://synthiam.com/Community/Questions/9137
@DJ
If a RegEx is used some other characters like () are a problem too.
EDIT: No problem with )
I'll close the ticket.
==== Resolution: not supported/By Design.
Where do you see () being a problem? An example would help me identify and repair it.
Regex: write once, read never...
if the content of the file has a "(" the error is:
I didn't check other combinations but if there is a RegEx involved,
i'm not a fan of regular expressions, although they are very useful.
oh - reading from a file - yeah. i will have to add a new function. A while ago there was a request to read code from a file with functions. This was implemented a long time ago but a function that reads which doesn't execute the function can be created.
I'll have to create a second version of file commands for that.