javascript - divide sentence string into substrings =< length of longest single word -
i newbie, , have pile of data strings (sentences). i'm trying divide each sentence substrings each string's length not exceed length of longest single word in sentence, , returning words in original sequence line breaks (photoshop carriage return, "\r") dividing substrings, sentence. words in each string not hyphenated (only full words or groups of words broken @ space be*).* edit: using maximum characters, longest word's character count... line have 2 or 3 words possibly, length of longest word.
i've found examples split , count array of words, order them character length, or add line breaks @ set characters, spaces, etc. none know enough see easy modification outcome. appreciated.
using replace can replace spaces \n
result.
a = 'this show navigation menu when scroll page 0px (in right-way). trying show after 200px (on page scroll-up) means not showing right way want show , hide after 200px when scroll \n page.' b = a.replace(/\s{1,}/g,"\n"); alert(b)
Comments
Post a Comment