-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathWrapWords.ahk
34 lines (25 loc) · 1.54 KB
/
WrapWords.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* Example
str =
(
example
example text more example text example text more example text example text more example text example text more example text
example text more example text example text more example text example text and more example text example text more example text
example text more example text example text more example text example text more example text example text more example text
example text more example text example text more example text example text more example text example and text more example text
example text more example text example text more example text example text and even more example text example text more example
text.
text example text more example text example text more example text example text more example text example text more example text
example text more example text example text more example text example text more example text example text and even more example
text example text more example text example text more example text example text more example text example text more example text
and even more text.
)
MsgBox, 64, Result, % WrapWords(str, 112)
*/
WrapWords(text, wrapCol) {
For lIndex, line in StrSplit(text, "`n", "´r")
For each, word in StrSplit(line := Trim(RegExReplace(line, "\h+", " ")), " ")
(StrLen(newLine) + StrLen(word) < wrapCol) ? (newLine .= (newLine > "" ? " " : "") word)
: (out .= (out > "" ? "`n" : "") newLine, newLine := word)
(!line) && (out .= (out > "" ? "`n" : "") newLine "`n", newLine := "")
return out (out > "" ? "`n" : "") newLine
}