Jump to content
Welcome to the new FusionPro User Forum! ×

Rule to find last comma and add space and word and after it.


maryj

Recommended Posts

I need help creating a FP rule that will go from the right and at the first comma add a space and the word "and", but not change any of the other commas if there are any. Is it possible to do this and if it is, can you tell how the rule would be?

 

Thanks!

Link to comment
Share on other sites

Try this.

 

Change the string between quote to your field (var lcString = Field("xyz"))

 

var lcString = "Looking for, the last comma, of string"

var lnPosition = lcString.lastIndexOf(",")

var part1 = Trim(lcString.substring(lnPosition ,-1));

var part2 = Trim(lcString.substring(lnPosition + 1 ));

return part1 + ' and ' + part2

Edited by Andre Globensky
translation of comma in french error, should of been , instead of . (period)
Link to comment
Share on other sites

Thanks Dan, that worked great, but now I need it to do one more thing. I need that same rule to add a space after the other commas in the field. This is what is in the field:

 

Home purchase/refinance,Business checking account,Business/commercial loans

 

I need the rule to make it say:

 

Home purchase/refinance, Business checking account, and Business/commercial loans

 

Is this possible with one rule?

 

Thanks,

 

Mary

Link to comment
Share on other sites

I need that same rule to add a space after the other commas in the field. This is what is in the field:

 

Home purchase/refinance,Business checking account,Business/commercial loans

 

I need the rule to make it say:

 

Home purchase/refinance, Business checking account, and Business/commercial loans

 

Is this possible with one rule?

return Field("YourFieldName").replace(/,([^,]*)$/, ",and $1").replace(/,/g, ", ");

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.

Guest
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...