I've looked everywhere for this, but I haven't had any results from suggestions in other discussions. I thought maybe it was somehow InDesign specific.
I'm trying to split a textframe's content by line breaks, in a file I didn't put together (and have no contact with the creator).
I initially tried
with no luck. ( split('\t'); did work to split by tabs )
I have since tried everything I can think of / found online,
split('¶ '); ( getting desperate 😕 )
When I alert the contents it is split on two lines, so I know the content is broken up.
And when I enable 'show hidden characters' it does show a ¶ character at the end of the lines I'm trying to split.
Does anyone know what character/code I should be using to split by?
Or is there somewhere in settings/preferences where I could specify the line break character for the document or paragraph style? ( I looked but couldn't find anything that sounded relevant)
This is slowly driving me crazy.
Any help would be very greatly appreciated!
I managed to get it to recognizes the paragraph return character!
In case it helps anyone else, here is the code that's working for me.
(with not surrounding quotation marks)
var s = "hi\nthere\n.";
// Result: [ "hi" , "there" , ". " ]
But I also get the same result with:
var s = "hi\nthere\n.";
Tested with ESTK 18.104.22.168.
This also works with InDesign's contents property of e.g. a text frame.
Even though the line break is a special character SpecialCharacters.FORCED_LINE_BREAK .
// Text frame selected
var s = app.selection.contents;
What is your string or contents you are running split() at?
If the contents of a text frame, can you show the text with hidden characters visible?
I don't see the regular paragraph return \r (single and on its own) in OP's own list of attempts. My guess the final combination [\r\n] only works because it is in there in the character class.
(And with that last one the analogy breaks. "\b" does NOT translate to "backspace" in InDesign's native text; it is one of the special types of tab.)
Thank you so much for sharing. I was going crazy trying to figure why my expression seemed blind to the line breaks.
Moved to InDesign Scripting.
Script works great! I know this is from a while back, but I'm wondering if there is a way to break up the line of text so it can be on two lines, as well as how to repeat the "pattern" so to speak so that it repeats top to bottom, left to right, to fill the image with the watermarked text. Does that make sense?
can you share a screenshot of the "before" and a screenshot of the "after"? I'm not entirely sure what you're looking to do.