maryj Posted August 29, 2011 Share Posted August 29, 2011 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! Quote Link to comment Share on other sites More sharing options...
Andre Globensky Posted August 29, 2011 Share Posted August 29, 2011 (edited) 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 August 29, 2011 by Andre Globensky translation of comma in french error, should of been , instead of . (period) Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 29, 2011 Share Posted August 29, 2011 return Field("YourFieldName").replace(/,([^,]*)$/, ", and$1"); Quote Link to comment Share on other sites More sharing options...
maryj Posted August 29, 2011 Author Share Posted August 29, 2011 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 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 29, 2011 Share Posted August 29, 2011 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, ", "); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.