.jpg?sfvrsn=3ad09b0a_1)
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:
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;
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
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
- 10.4K All Categories
- 5.3K RobotStudio
- 345 UpFeed
- 15 Tutorials
- 8 RobotApps
- 281 PowerPacs
- 404 RobotStudio S4
- 1.7K Developer Tools
- 238 ScreenMaker
- 2.6K Robot Controller
- 246 IRC5
- 36 OmniCore
- 6 RCS (Realistic Controller Simulation)
- 3 RobotStudio AR Viewer
- 689 RAPID Programming
- 14 Wizard Easy Programming
- 101 Collaborative Robots
- 3 Job listings