none
writing text to fle with newlines RRS feed

  • Question

  • Hello,

    I have a string read from a file which has many lines in it.

    I wish to remove some of the parts (which works) but also add some more lines.

    I have been using Text.GetCharacter(010) for my newline character which displays perfectly.

    My problem is when I later save this string to a file, odd characters are saved, not new lines.

    I have tried using (013) instead to no avail.

    How should I add newlines to a multiline strings so they save correctly ?

    Many thanks for your help,

    Tom

    Wednesday, March 9, 2011 5:55 PM

Answers

  • Hi,

    Try using character 10, then open with wordpad rather than notepad.

    Or use (13)+(10) to see in notepad as well.

    newline = Text.GetCharacter(13)+Text.GetCharacter(10)
    sample = "This is line 1"+newline+"This is line 2"
    File.WriteContents(Program.Directory+"\test.txt",sample)

    The way to work this out was to create a sample text in notepad and read it in and see the character codes.

    sampleIn = File.ReadContents(Program.Directory+"\test.txt")
    For i = 1 To Text.GetLength(sampleIn)
      char = Text.GetSubText(sampleIn,i,1)
      TextWindow.WriteLine(char+" : "+Text.GetCharacterCode(char))
    EndFor

    • Proposed as answer by litdevModerator Friday, March 11, 2011 9:11 PM
    • Marked as answer by TomTheTom Monday, March 14, 2011 7:30 AM
    Wednesday, March 9, 2011 7:06 PM
    Moderator

All replies

  • Hi,

    Try using character 10, then open with wordpad rather than notepad.

    Or use (13)+(10) to see in notepad as well.

    newline = Text.GetCharacter(13)+Text.GetCharacter(10)
    sample = "This is line 1"+newline+"This is line 2"
    File.WriteContents(Program.Directory+"\test.txt",sample)

    The way to work this out was to create a sample text in notepad and read it in and see the character codes.

    sampleIn = File.ReadContents(Program.Directory+"\test.txt")
    For i = 1 To Text.GetLength(sampleIn)
      char = Text.GetSubText(sampleIn,i,1)
      TextWindow.WriteLine(char+" : "+Text.GetCharacterCode(char))
    EndFor

    • Proposed as answer by litdevModerator Friday, March 11, 2011 9:11 PM
    • Marked as answer by TomTheTom Monday, March 14, 2011 7:30 AM
    Wednesday, March 9, 2011 7:06 PM
    Moderator
  • Fantastic, thank you very much.
    Monday, March 14, 2011 7:30 AM