I created a script that will take long comments and break them at 80 characters and wraps them to the next line with a continuation symbol.
Unfortunately, it breaks things mid-word. So the above line might end up like:
"I created a routine that will take comments and break them at 80 characters and wrap them to the ne
+ xt line with a continuation symbol."
The following script takes the string (f) and puts it out to my GENERAL NOTES page at line (position) . The page is a series of text fields called GeneralNotes.1-GeneralNotes.xx. If the string is too long, it breaks it at 80 characters and put the remainder on the next line with a "+" , increments the counters, and keeps going. This WORKS. It does assume that the longest would be TWO full lines though. I am sure it could be writen to be smarter, but for now I am working on something else....
{
if (f.valueAsString.length > 80) {
var firstpart = f.valueAsString.slice(0,80); //this -SHOULD- be the first 80 char
var leftover = f.valueAsString.slice(80); //this -SHOULD- be the remainder.
s.value = firstpart;
position += 1;
s = this.getField("GeneralNotes."+ position);
s.value = " + "+leftover;
position += 1
}
else
{
s.value = f.value; //stuff Export value into currnet notes field
position += 1; //increment the notes line
}
}
HOWEVER, I would like to re-work it to look backwards to the nearest space(sp) so that it doesn't break words apart. (like ne +xt in the above example)
Is there an easy way to do this? How about the first (sp) after 75 characters? Is there an easy way (other than just replicating the code) to extend this to 3 lines or more?