iOS Question [Solved] Issue with File.ReadString - Works in B4A/J fails in B4i

MrKim

Well-Known Member
Licensed User
Longtime User
Edit: Solution is in Post #3.
Note:
This also solved a problem where dashes(-) did not display correctly in WebView even though they displayed fine in a browser.

I have several html files that I need to read in and edit. I am using File.readstring to read them in to a variable then editing. One of them fails but only in B4i
the error is
B4X:
<B4IExceptionWrapper: Error Domain=caught_exception Code=0 "Error reading file. Incorrect encoding" UserInfo={NSLocalizedDescription=Error reading file. Incorrect encoding}>
If I rem the error trapping I get:
B4X:
Error occurred on line: 71 (PageHelp)
Error reading file. Incorrect encoding
Stack Trace: (
  CoreFoundation       <redacted> + 252
  libobjc.A.dylib      objc_exception_throw + 56
  CoreFoundation       <redacted> + 0
  ALA Phone            -[B4IFile ReadString2:::] + 468
  ALA Phone            -[B4IFile ReadString::] + 120
  CoreFoundation       <redacted> + 144
  CoreFoundation       <redacted> + 292
  ALA Phone            +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1608
  ALA Phone            -[B4IShell runMethod:] + 448
  ALA Phone            -[B4IShell raiseEventImpl:method:args::] + 1648
ALA Phone            -[B4IShellBI raiseEvent:event:params:] + 1580
ALA Phone            __33-[B4I raiseUIEvent:event:params:]_block_invoke + 60
libdispatch.dylib    <redacted> + 24
libdispatch.dylib    <redacted> + 16
libdispatch.dylib    <redacted> + 1068
CoreFoundation       <redacted> + 12
CoreFoundation       <redacted> + 1924
CoreFoundation       CFRunLoopRunSpecific + 436
GraphicsServices     GSEventRunModal + 104
UIKitCore            UIApplicationMain + 212
ALA Phone            main + 128
libdyld.dylib        <redacted> + 4
)

After much fooling around I isolated the part of the file where the issue occurs.
This Fails (Again, only in B4i):
B4X:
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal;text-autospace:none'><span lang=EN-CA
style='font-size:14.0pt'>The menu is accessed by pressing the 'Hamburger' (</span><span
style='font-size:13.0pt;font-family:"Arial","sans-serif"'>&#8801;</span><span
lang=EN-CA style='font-size:14.0pt'>) icon in the upper left.</span></p>
This does not:
B4X:
<p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
text-align:center;line-height:normal;text-autospace:none'><span lang=EN-CA
style='font-size:14.0pt;mso-ansi-language:EN-CA'>The menu is accessed by
pressing the 'Hamburger' () icon in the upper left.</span></p>
The file is an MS Word document saved as an html file so there should be no problem loading it.

FYI The difference is actually the loading of a high bit character that looks like the 'Hamburger" icon. That would be the
&#8801

I can work around the problem but perhaps this is a bug that needs to be looked at?
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
It just shouldn't be this obscure. Thank you Microsoft.
For anyone else with this problem the answer is here.
Follow the steps under;
Choose an encoding standard when you open a file

On the version of Word I use (2010) it was a little different. File>Options>Advanced,>General then click Web Options, choose the encoding tab, then save document as Unicode (UTF-8). Make sure you pick the RIGHT Unicode, and make sure you check the box to always save or the next time you save the file you will be right back where you started from.
1615121872569.png
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Most important: use Notepad++. Open the text file and check its encoding.
So much to learn. When you spent your life working only with MS/Windows so many things were seamless that just aren't in the rest of the world.
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Most important: use Notepad++. Open the text file and check its encoding.
What really threw me, Erel - and I spent hours analyzing this trying to find the problem before posting, was that two other files which I created a while ago, have been working just fine. One of them was much more complex than the one that failed. So, of course I created my third file and tested it in B4j where it was just fine. It wasn't until days later that I discovered almost by accident that it failed in B4I. They were all, by the way,
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">.
 
Upvote 0
Top