Random fonts and sizes when saving txt file


I use this simple method for saving files on my app

[code] Dim f as FolderItem
f=new FolderItem(sentiero, folderitem.PathTypeAbsolute)‘sentiero is fhe path passed on this method
question=app.SortQuestions(question)’ sorts the questions’this is a string array that has the content that is being saved on the file

Dim i as integer

If f <> Nil then
Dim t as TextOutputStream = TextOutputStream.Create(f)

    t.writeline str(GameMode)'puts game mode on the first line
    for i=0 to question.Ubound
      t.WriteLine question(i)
    t = nil
  End Try
Catch 'e as IOException
  msgbox "savefile: error IOException"
  //handle error
End Try

End if[/code]

As you can see it’s a very basic saving text files method, but when I check out the outcome (the text files) I find that some lines have different sizes or fonts than the
other, it seems to be totally random. What could be the cause ?


What is the extension of the file you are saving and what are you using to view it?

Plain txt files and I’m viewing them with Window’s notepad.
It couldn’t get any “plainer” than this.

My guess is that this is an encoding problem, i.e., NotePad is having trouble with UTF-8. If I’m right, not all of the data shows up in NotePad as some characters will be missing.

See what happens if you replace the code that writes the line with:

t.WriteLine question( i ).ConvertEncoding( Encodings.WindowsANSI )

If all this is correct, you might have to include a BOM at the start of the file to tell NotePad (and other apps) that the content is encoded as UTF-8. Or use something better than NotePad.

Also see this page, just found via Google:


For more information on the BOM, see:


FYI, my M_String package has tools to make setting and interpreting the BOM easier.

The very strange part is that Notepad does not support diverse fonts. When a font is selected, it affects the entire text. When styled text is pasted into it, it becomes the default font.

My first reflex would be to open the file in other applications. For instance WordPad, to see if the same phenomenon occurs at the same place.

I suspect it may have to do with control characters in the document.

An Hex editor would help track down what’s in there.