Cycle 2: Built-in Function ReplaceAll(searchString,replacementString)

Cycle 2: Built-in Function ReplaceAll(searchString,replacementString)

I am re-submiting the suggestion to have a ZOHO Creator built-in function to replace "all specified character patterns in a named field/variable" with "another specified character pattern".


Suggestion:


Provide a ZOHO Creator built-in function that will replace all occurences of a specified SubString within a specified String (field or variable) with another specified String.

Purpose:

Perform Text Replacement operations ...

- easily ... one simple command instead of recursively calling a User Defined Function
- quickly ... avoid delays inherent in servicing Deluge scripts
- without exceeding limits/caps imposed by ZOHO Creator for number of Deluge commands serviced per user action


Motivation:

Deploy such functionality to easily create ...

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

- customized Bulk Edit solutions ... by iterating through records that met a required criteria ... then replace all occurences of valueA in FieldX to valueB.

- 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


Implementation:

resultVariable = sourceVariable.ReplaceAll(searchString,replacementString);

                             
  1.  //e.g. 1
  2. sourceVariable = "Jack and Jill went to Jack's place in the city";
  3. searchString = "Jack";
  4. replacementString = "Bill"
  5. resultVariable = sourceVariable.ReplaceAll(searchString,replacementString);
  6. //returns "Bill and Jill went to Bill's place in the city"


  7. //e.g. 2
  8. input.Address = "Suite 123, 4523 Yonge Street, Toronto";
  9. input.Address = input.Address.replaceAll("23","9945");
  10. //returns "Suite 19945, 459945 Yonge Street, Toronto"


  11. //e.g. 3
  12. sourceString = "ABCDEFGH";
  13. answerString = sourceString.ReplaceAll("BCD", "");
  14. //returns "AEFGH"


  15. //e.g. 4
  16. templateMessage = Templates_R_Us [templateID = "V.I.P Offers"];
  17. for each VIPCustomer in Customer [Status == "V.I.P"]
  18. {
  19.    customMessage = templateMessage.TemplateData.ReplaceAll("{fname}",VIPCustomer.FirstName);
  20.    customMessage = customMessage.ReplaceAll("{lname}",VIPCustomer.LastName);
  21.    //etc. etc.

  22.    sendmail
  23.    (
  24.       To : VIPCustomer.EmailID
  25.       From : zoho.adminuser
  26.       Subject : "Special Offer to VIP Customerts"
  27.       Message : customMessage
  28.    )

  29. }


  30. //e.g. 5
  31. templateHTML = Templates_R_Us [templateID = "Dashboard"];
  32. customHTML = templateHTML.TemplateData.ReplaceAll("{fname}",input.FirstName);
  33. customHTML = customHTML.ReplaceAll("{lname}",input.LastName);
  34. etc.
  35. <%=customHTML%>;

Issues:



























Can't think of any ... this is a pretty basic function available in most script languages.


Workaround:

Experienced Developers can develop a User Defined Function that ...

- replaces one instance of the specified character pattern using available built-in functions like .getPrefix() and .getSuffix()

- recursively calls itself until there are no more instances of the specified character pattern

However, this can consume a large number of Deluge script commands ... which can not only affect performance (response time) ... but exceed the limits/caps imposed by ZOHO Creator for the number of Deluge scripts serviced per user action.



Free ZOHO Creator Application for anyone that votes for this suggestion


Gaev