Copy link to clipboard
Copied
Hi everyone,
I would like to split my source text up to single words. text.sourceText.split(" ") works, but it doesnt take line breaks into account. I thought this would be the solution:
text.sourceText.split(" ", "\r")
I e splitting the text up either by spaces or line breaks, but it doesn't work.
What am I doing wrong?
Best,
Mikael
You need to replace line breaks with spaces and then split spaces
text.sourceText.replace(/\r/g,"\r ").split(" ")
Copy link to clipboard
Copied
You need to replace line breaks with spaces and then split spaces
text.sourceText.replace(/\r/g,"\r ").split(" ")
Copy link to clipboard
Copied
I had tried something similar but that didn't work. After some troubeshooting I found that it only replaced the first instance of a linebreak. This is how I finally got it to work:
text.sourceText.replace(/\r/g, "\r ").split(" ")
Thank you!
Copy link to clipboard
Copied
The "g" for global (to keep replacing line breaks after the first instance. The "\r " (including a space) since I wanted to keep the line break.
Copy link to clipboard
Copied
Some simple regex trickery probably works just as well, since all string functions should handle regular expressions without explitly having to declare them:
text.sourceText.split(" "|"\r")
Mylenium
Copy link to clipboard
Copied
I thought I tried that, maybe I was just typing it wrong. But problem now solved, thank you!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now