quirks in writing text to file lazarus / 12-Debugger ---------------------------------------------------------------------- daringly · 2023-10-07 22:16 These two codes give very different output. There is a weird character in teststring that disables output to the textfile, and it looks like '' or ", not sure which. assign(fila); rewrite(fila); writeln(fila,teststring); close(fila); vs writeln(teststring); These two codes give very different output. There is a weird character in teststring that disables output to the textfile. The second time you write this code, writing to the file works normally. If I look at the string's first character in debug, I get pchar: 77 'M' String: 34 '\"' How can I identify and remove this escape code from the string so that the visual and file output are similar? ---------------------------------------------------------------------- Martin_fr · 2023-10-07 22:58 Quote from: daringly on October 08, 2023, 12:16:59 am If I look at the string's first character in debug, I get pchar: 77 'M' String: 34 '\"' About the debuggers output. Depending on various things, the fpc compiler does not give the debugger enough info if your variable is a pchar, or a string. However if you watch something like "MyText[1]" in a string "[1]" means the first char. A pchar however starts at index 0, sot "[1]" is the 2nd char. => the debugger shows both. For the rest I am not sure, 77 would be M 32 would be "  (not sure why it is shown with a \ before) I don't know why they affect your file. Have you looked at it in a hex editor? Also why do you only look at the FIRST char in the debugger? Maybe the issues is a later char? ---------------------------------------------------------------------- daringly · 2023-10-07 23:10 Thanks. I looked at 0 and 1. Everything after the first 2 characters is "normal" compared to other strings that work normally. With string[0], pchar is 34. When I removed that first character (using rightstr, skipping first character) the text file worked correctly. ---------------------------------------------------------------------- TRon · 2023-10-08 06:49 Quote from: daringly on October 08, 2023, 01:10:30 amWhen I removed that first character (using rightstr, skipping first character) the text file worked correctly. In which case that can only lead to one conclusion and that is that the 'wrong' character was already present in your teststring otherwise it would not have ended up in your file. It could be the 'wrong' character isn't printable in the terminal (e.g. presentable by a visible ascii/utf character). Anything else without compilable code that is capable of reproducing the error is just pure speculation. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program test; {$mode objfpc}{$H+} uses  sysutils; procedure WriteTestString(teststring: string);var  fd: textfile;begin  // write to terminal  WriteLn(teststring);   // write to file  AssignFile(fd, 'some_test_file.txt');   {$push}  {$I+}  try    Rewrite(fd);    writeln(fd, teststring);    CloseFile(fd);  except    on E: EInOutError      do writeln('ERROR: error occurred during file operation: ', E.ClassName, ' / ', E.Message);  end;  {$pop}end; begin  WriteTestString('"This is a test string."');end.