Jump to content

how to remove text?


Recommended Posts

hello, i have a field named Title in my template. in this field there will be different job titles flowing in, but as an example lets use the bottom title:

DBA / CDC: Marketing Manager

what i need is a rule that will remove anything before the ":" but then also remove the ":" and space after it. i should end up with just:

Marketing Manager


the common denominator in all job titles that flow into the template is the ":" character and space afterward.

Link to comment
Share on other sites

I didn't actually test this, but I believe it's correct:

var title = Field("Title");
// determine position of colon in string
var colonLoc = title.indexOf(":");
// remove chars to left of colon plus colon itself
title = Right(title, title.length-colonLoc-1);
// remove any leading or trailing spaces
title = Trim(title);
return title;

Link to comment
Share on other sites

In this case a split would work nicely. The CustType would be equal to everything to the left of the colon character and CustType2 would be equal to everything on the right of the colon. Using the .split would be similar to using TextToColumns in Excel. Whatever character you enter inside the quotes becomes your delimiter. Since it is zero based the 1st value is [0], the second value is [1], and so on...







Link to comment
Share on other sites

  • 8 years later...
Hi all, could anyone tell me the code to remove a character to the right of a field? Lets say the "name" field contains someones name but there is an asterisk directly next to it. Can I keep the name and remove the asterisk?




You can try this:

var corName = Field("Name"); // Replace with your field name.

corName = corName.replace(/\*$/, ''); // If there is more than one asterisk, this removes the last asterisk only.

return Trim(corName); // Trims all leading and trailing white space and returns your field with the last asterisk removed.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...