Built-in Function ReplaceAll(searchString,ReplacementString)

Built-in Function ReplaceAll(searchString,ReplacementString)

Following my own suggested guidelines for proposing a Community Feature for the very first cycle, I suggest that ZOHO Creator provide a new built-in String Function that would ...

Replace all Occurences of a specified SubString within a specified String (field or variable) with another specified SubString

... for example ...
sourceVariable = "Jack and Jill went to Jack's place in the city";
searchString = "Jack";
replacementString = "Bill"
resultVariable = sourceVariable.ReplaceAll(searchString,replacementString); 
//returns "Bill and Jill went to Bill's place in the city"


input.Address = "Suite 123, 4523 Yonge Street, Toronto";
input.Address = input.Address.replaceAll("23","9945");
//returns "Suite 19945, 459945 Yonge Street, Toronto"

sourceString = "ABCDEFGH";
answerString = sourceString.ReplaceAll("BCD", "");
//returns "AEFGH"




Currently, it is possible to ...

- replace one instance of a substring within a string with another substring using getPrefix(), getSuffix() and then reconstructing the new string with the results of the previous commands

- replace multiple instances of the same substring by recursively calling a Function with the above script


... however, it is inefficient (to code and run), and consumes valuable limited command limits per action ... so a ReplaceAll() built-in function would be preferable.

Avaialbility of an easy to use ReplaceAll function would make it easy to deploy template text that could have specific content replaced by other values.

One area where this could be deployed is in the creation of customized email messages ... templates could be read into variables ... substrings for items like names and addresses could be replaced within the variables ... and the resullting variable content could be the target of a sendmail command.

Another area of use would be in HTML Views ... instead of the current method of interlacing HTML and Deluge scripting, the entire HTML content could be stored as a template ... then read into a variable and have specific subStrings replaced before being output e.g. ...
templateHTML = Templates_R_Us [templateID = "Dasboard"];
customHTML = templateHTML.ReplaceAll("{fname}",input.FirstName);
customHTML = customHTML.ReplaceAll("{lname}",input.LastName);
etc.
<%=customHTML%>;



It could also be useful when all occurences of valueA need to be changed in FieldX of all records to valueB.


As a feature requiring relatively fewer development resources and providing a variety of beneficial applications to both novices and experienced users, I think this feature is a good candidate for consideration as the first Community Feature.


Gaev