Detect and remove UTF8-BOM Header
Hey,
I am reading a text string from a .txt file in the HOME dir.
When I edit that file on the (real) robot controller in RobotStudio, it will be encoded in UTF8-BOM and the 3 byte header: "" is added at the beginning of the file.
What would be the best way to detect and remove the BOM header out of the string I read with:
VAR iodev io;
VAR string str;Open file,io\Read;str:=ReadStr(io \RemoveCR\DiscardHeaders);Close io;
my fear is that I can´t just have the string "" in the source code. Other UTF8 non ASCII glyphs (like äöü) are occasionally destroyed and replaced with other glyphs while saving/loading.
Thanks in advance
I am reading a text string from a .txt file in the HOME dir.
When I edit that file on the (real) robot controller in RobotStudio, it will be encoded in UTF8-BOM and the 3 byte header: "" is added at the beginning of the file.
What would be the best way to detect and remove the BOM header out of the string I read with:
VAR iodev io;
VAR string str;Open file,io\Read;str:=ReadStr(io \RemoveCR\DiscardHeaders);Close io;
my fear is that I can´t just have the string "" in the source code. Other UTF8 non ASCII glyphs (like äöü) are occasionally destroyed and replaced with other glyphs while saving/loading.
Thanks in advance
0
Best Answer
-
Fixed it,
to not use non-ascii-glyphs in the source code, one can also use the hex representation of the BOM-Header like so:VAR iodev io;VAR string str;Open file,io\Read;str:=ReadStr(io \RemoveCR\DiscardHeaders);Close io;! remove UTF8-BOM 3 bytes header, if availableIF StrPart(str, 1, 3) = "\ef\bb\bf" THENstr := StrPart(str, 4, StrLen(str)-3);ENDIF0
Answers
-
Try IF str := "" THEN
! do nothing
ENDIF
Lee Justice0 -
so are these glyphs "" ok to have in source code? "äöü" do make problems in our comments0
-
If you were to try to view an encrypted module, you would see many strange characters, and so I could guess that the controller might be confused as to whether the module is encrypted or not with those characters present.Lee Justice0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings