From: "Jarle Leirpoll" Received: from nmsh6.e.nsc.no ([148.123.160.200] verified) by media-motion.tv (CommuniGate Pro SMTP 6.1.0) with ESMTP id 6434131 for AE-List@media-motion.tv; Wed, 11 Apr 2018 09:27:42 +0200 X-Auth: leirpoll@online.no Received: from HPZBook17 (52.69.164.82.customer.cdi.no [82.164.69.52]) (authenticated bits=0) by nmsh6.nsc.no (8.15.2/8.15.2) with ESMTPSA id w3B7X2XT019899 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 11 Apr 2018 09:33:02 +0200 To: "'After Effects Mail List'" Subject: Expression to break text after a certain number of characters Date: Wed, 11 Apr 2018 09:33:01 +0200 Message-ID: <000001d3d167$52f68280$f8e38780$@online.no> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdPRZN6Gib+qQkGfRFyFyAo9VMpzXA== Content-Language: no X-Scanned-By: MIMEDefang 2.78 I found this expression from Dan Ebberts, and it works beautifully until the source text has line breaks. After the line breaks, the first lines get shorter. It seems to add the characters from the line above the break to the character count. See this image: https://www.dropbox.com/s/a842o913cxhyeua/LineBreakTrouble.png?dl=0 Is there a way to make this code aware of line breaks too, so that it just keeps the line breaks from the source and starts on a new line with the correct length? The goal is that the user should just copy-paste text from a word document or similar, into a field - and it should just work. /jarle txt = thisComp.layer("Source Text").text.sourceText; n = thisComp.layer("Controls").effect("Text width")("Slider"); outStr = ""; newLine = "" splt = txt.split(" ") for (i = 0; i < splt.length; i++){ if ((newLine + " " + splt[i]).length > n){ if (outStr != "") outStr += "\r"; outStr += newLine; newLine = splt[i]; }else{ if (newLine != "") newLine += " "; newLine += splt[i]; } } if (newLine != ""){ if (outStr != "") outStr += "\r"; outStr += newLine; } outStr;