MarcomCentral (PTI) and FusionPro User Communities

MarcomCentral (PTI) and FusionPro User Communities (http://forums.pti.com/index.php)
-   Formatting Text (http://forums.pti.com/forumdisplay.php?f=32)
-   -   Trimming Text based on character count (http://forums.pti.com/showthread.php?t=10617)

Dmiller35 December 30th, 2021 08:20 AM

Trimming Text based on character count
 
I have a document that has a limited amount of space and one of the fields is an email address. I can do a copyfit, but in order to keep everything on one line, the font has to go from 9pt down to 5 on some records. (The client's domain name is stupidly long).

Is there a way to splt the email at the "@" so that when it's longer that 32 characters, it drops the "@unecessarilylongdomain.com" down to a second line?
Every record has the same domain name so is there a way to trim the right 25 characters?

This way jonathan.doe@unecessarilylongdomain.com would become
jonathan.doe
@unecessarilylongdomain.com

Susan December 30th, 2021 02:14 PM

Re: Trimming Text based on character count
 
I've used this rule which uses the width of your text box and will break the email address if it doesn't fit.


// Use TextMeasure to get the length of each email
var tm = new FusionProTextMeasure;
var frameWidth = 2.5; // set width of the text box (in inches)
tm.pointSize = "10 pt"; // set the type size
tm.font = "Calibri"; // set your typeface
var str = Field("email address"); // set the field to use
tm.CalculateTextExtent(str);
tm.useTags = false;
var tmWidth = tm.textWidth;

return (tmWidth < frameWidth*7200) ? str : str.replace("@unecessarilylongdomain.com", "<br>@unecessarilylongdomain.com");

jwhittaker December 31st, 2021 05:15 AM

Re: Trimming Text based on character count
 
D Miller
You could try something like this? I know there is a more efficient way but this should still work.

if (Len(Field("Email")) >= 32)
{
var emailarray = Field("Email").split("@");
return emailarray[0] + '<p>' + "@" + emailarray[1];
}
else
return Field("Email");

Dmiller35 January 6th, 2022 07:27 AM

Re: Trimming Text based on character count
 
Thanks Susan. That worked great.


All times are GMT -7. The time now is 07:51 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.