repairtextfileEOF

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - File handling
Introduced first in SolidGeometry 5.5, Creation date: 2025-06-18, Last change: 2025-09-15

Removes unwanted EOL char(26) from text files

Description

For some reason, in 2024a and 2024b, when writing with fid=fopen(fname,'wt+','n',"ISO-8859-15"); fwrite(fid,txt,'uint8'); at least on MAC under macOS 14 and macOS 15, EOF characters char(26) occasionally appear in the file. This happens when writing, not when reading. Since this character causes problems with parsing XML files in the browser, such files can be corrected retrospectively using this function, even though the same write routine is used here.[spchk]

See Also: writetextfile , readtextfile

Example Illustration

 missing image of repairtextfileEOF(fname)

Syntax

repairtextfileEOF(fname)

Input Parameter

fname: full filepath

Examples


repairtextfileEOF('/Volumes/LUETH-WIN/WIN AIM Matlab Libraries/SolidGeometry-Code/demos.xml')




Copyright 2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function, repairtextfileEOF, is designed to remove unwanted EOF characters (char(26)) from text files. These characters can cause issues when parsing XML files in browsers. The function is part of the SolidGeometry library and was introduced in version 5.5.

Input Parameters

Algorithm Steps

  1. Read the content of the file specified by fname using the readtextfile function. Store the content in the variable txt.
  2. Identify all occurrences of the EOF character (char(26)) in txt and store the result in the variable eol.
  3. Find the first occurrence of the EOF character using find(eol, 1) and store the result in fff.
  4. Remove all EOF characters from txt by selecting only those elements that are not EOF characters.
  5. If fff is not empty, indicating that EOF characters were found:
  6. If fff is empty, indicating no EOF characters were found:
Algorithm explaination created using ChatGPT on 2025-08-19 01:31. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21