[ad_1]
I want to wrap simple text in a <span>
object by getting its innerText (which I can do) and replacing it with text that has been wrapped even if only with \n
used in place for new lines.
I’ve found this answer But there wasn’t an example provided of how to use it.
// Static Width (Plain Regex)
const wrap = (s) => s.replace(
/(?![^\n]{1,32}$)([^\n]{1,32})\s/g, '$1\n'
);
Lets say my string is defined as below
let stringName = "Here is my really long string, that I want to wrap every 20 or so characters"
let wrapNum = 20;
let newString = wrapFuntion(stringName, wrapNum);
From the comments on the answer it’s probably easy for anyone with JavaScript experience, or I’ve missed something most find obvious in the answer. Just looking to learn.
my score is too low to comment on original answer
[ad_2]