none
Add quotes in quotes RRS feed

  • Question

  • Hello there,

    I wrote a line of program like this:

      File.InsertLine(txt,lineNum+1,"GraphicsWindow.Title = "Molecular Basic 2"")

    But the editor told me that "Molecular" and "Basic" are variables. I want to write this in a TXT file:

    GraphicsWindow.Title = "Molecular Basic 2"

    So I changed it to this:

      File.InsertLine(txt,lineNum+1,"GraphicsWindow.Title = 'Molecular Basic 2'")

    After changing, I ran the program, then had a look in the TXT file, the output is:

    GraphicsWindow.Title = 'Molecular Basic 2'

    Wrong, not ', but "! I tried a lot, such as 

    File.InsertLine(txt,lineNum+1,"GraphicsWindow.Title = ""Molecular Basic 2"")

    , but still not work.

    How can I make it?

    Best Regards & Thanks!

    Wednesday, August 12, 2020 1:48 PM

Answers

  • Define a variable e.g.   Q34=Text.GetCharacter(34)  and use this to put a double quote in a textline

    testtext="Title = "+Q34+"Molecular Basic"+Q34


    Jan [ WhTurner ] The Netherlands

    Wednesday, August 12, 2020 2:55 PM
    Answerer
  • use ldtext.replace

    urstr=" 'Molecular Basic 2'

    urstr=ldtext.replace(urstr "'" Text.GetCharacter(34))

    Wednesday, August 12, 2020 7:34 PM

All replies

  • Define a variable e.g.   Q34=Text.GetCharacter(34)  and use this to put a double quote in a textline

    testtext="Title = "+Q34+"Molecular Basic"+Q34


    Jan [ WhTurner ] The Netherlands

    Wednesday, August 12, 2020 2:55 PM
    Answerer
  • use ldtext.replace

    urstr=" 'Molecular Basic 2'

    urstr=ldtext.replace(urstr "'" Text.GetCharacter(34))

    Wednesday, August 12, 2020 7:34 PM
  • Both work! Thank you so much!

    WhTurner33's code:

      quote = Text.GetCharacter(34)
      File.InsertLine(txt,lineNum+1,"GraphicsWindow.Title = "+quote+"Molecular Basic 2"+quote)

    Tryhest's code:

      urstr=" 'Molecular Basic 2'
      urstr=ldtext.replace(urstr "'" Text.GetCharacter(34))
      File.InsertLine(txt,1,"GraphicWindow.Title = "+urstr)

    Best Regards & Thanks again!

    Thursday, August 13, 2020 1:25 AM