macfan55 Posted January 30, 2018 Share Posted January 30, 2018 Hi out there; my first question is this: How can I make a rule that removes a specific word from a text string and make a new variable out of the remaining text. Help is appreciated here! Quote Link to comment Share on other sites More sharing options...
jwhittaker Posted January 30, 2018 Share Posted January 30, 2018 return ReplaceSubstring(Field("string"),'texttoreplace', 'replacementtext'); Quote Link to comment Share on other sites More sharing options...
macfan55 Posted January 31, 2018 Author Share Posted January 31, 2018 Thanks! Works great. 1 question about the search and replace field; Can I use a "wildcard" in the texttoreplace field as a part of it? Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted January 31, 2018 Share Posted January 31, 2018 Thanks! Works great. 1 question about the search and replace field; Can I use a "wildcard" in the texttoreplace field as a part of it? You can do that with JavaScript's String.replace function and a Regular Expression. You can find lots of examples online by searching for "JavaScript replace wildcard", such as: http://www.brighthub.com/internet/web-development/articles/85831.aspx If you have a more specific question about how to replace something, then I, or someone else here, could provide a more specific answer. Quote Link to comment Share on other sites More sharing options...
macfan55 Posted February 5, 2018 Author Share Posted February 5, 2018 Thanks for your answer; The problem I now have is that the word I want to replace is mostly "Location" and sometimes "location" so I was looking for a way to use a wildcard for the first letter like "*ocation" but that does not work. Maybe You can show me the right way to do that as a part of the replace substring code. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
ScottHillock Posted February 6, 2018 Share Posted February 6, 2018 var Var1 = Field("name"); return Var1.replace(/([lL]ocation)+/g,"test"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted February 6, 2018 Share Posted February 6, 2018 var Var1 = Field("name"); return Var1.replace(/([lL]ocation)+/g,"test"); Or just add the "i" flag to the Regular Expression to do a case-insensitive match/replacement: return Field("YourFieldName").replace(/location/gi, "new text"); Quote Link to comment Share on other sites More sharing options...
macfan55 Posted February 9, 2018 Author Share Posted February 9, 2018 Thanks four your great help! It works perfect!! 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.