Code: Select all
@FILE 1, "myFile.xml"
...
moai.CreateApp(FileToString(1))
I load and utilize files with ease using ie. @BRUSH, but with this I get:
Code: Select all
Error in line 178 (myApp.hws): Cannot read file 1 !
Code: Select all
@FILE 1, "myFile.xml"
...
moai.CreateApp(FileToString(1))
Code: Select all
Error in line 178 (myApp.hws): Cannot read file 1 !
Code: Select all
moai.CreateApp(FileToString("myFile.xml"))
Yes, I know it works without using the id.Tipsi wrote:The command FileToString() works without id.
Thank you, SamuraiCrow. This is probably the right track.SamuraiCrow wrote:Try reading this post.
Code: Select all
;moai.CreateApp(FileToString("myFile.xml"))
@FILE 1, "myFile.xml"
moai.CreateApp(ReadString(1, FileLength(1)))
Code: Select all
Error in line 186 (myFile.hws): Could not read all characters from file!
Check if it is read protected!
Code: Select all
moai.CreateApp(ConvertStr(ReadBytes(1), #ENCODING_ISO8859_1, #ENCODING_UTF8))
Thank you! Will try that.airsoftsoftwair wrote:ReadString() operates in characters, FileLength() in bytes. If your file is not in UTF-8, you first need to read the raw bytes and then convert them to UTF-8 using ConvertStr(), e.g. something like this:
Code: Select all
moai.CreateApp(ConvertStr(ReadBytes(1), #ENCODING_ISO8859_1, #ENCODING_UTF8))
Code: Select all
moai.CreateApp(UnRightStr(ConvertStr(ReadBytes(1), #ENCODING_ISO8859_1, #ENCODING_UTF8), 3))
Yes, this is a 3-byte sequence known as the UTF-8 BOM. It is not necessary but can be there. Often text editors make it optional as to whether a BOM is generated or not.Figgy78 wrote:Initially I couldn't get the conversion of the xml-file to UTF-8 to work, but then I discovered that the file has a few cryptic characters at the beginning. I understand this has to do with identifying the Encoding?
Actually, if your text file is already UTF-8, you don't have to do the conversion at all. Just skip the first three bytes and then use ReadString(), like this:Anyway. I solved this by stripping out the first three characters of the resulting string.
Code: Select all
Seek(1, 3)
moai.CreateApp(ReadString(1))
Code: Select all
- Change: ReadChr() and ReadString() automatically skip the UTF-8 BOM now whenever they operate
in Unicode mode