JavaScript string newline character?

后端 未结 15 2204
终归单人心
终归单人心 2020-11-22 08:06

Is \\n the universal newline character sequence in Javascript for all platforms? If not, how do I determine the character for the current environment?

I

15条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 08:19

    A note - when using ExtendScript JavaScript (the Adobe Scripting language used in applications like Photoshop CS3+), the character to use is "\r". "\n" will be interpreted as a font character, and many fonts will thus have a block character instead.

    For example (to select a layer named 'Note' and add line feeds after all periods):

    var layerText = app.activeDocument.artLayers.getByName('Note').textItem.contents;
    layerText = layerText.replace(/\. /g,".\r");
    

提交回复
热议问题