79550934

Date: 2025-04-02 14:43:50
Score: 0.5
Natty:
Report link

To make things work we need to use the method replaceText() to replace a text in the document body then using the reverse() method to reverse the text.

Sample Script:

function myFunction() {
  const docs = DocumentApp.getActiveDocument();
  const body = docs.getBody();
  // store your variable names with value here
  const [varOne, varTwo, varThree] = ["foo", "bar", "sample"]

  // reverse the string by converting the it into array by using split and convert it back to string by using join method
  const reverseText = (string) => {return string.split("").reverse().join("")}

  // using replaceText to replace a text in the body
  body.replaceText("{variableOne}", reverseText(varOne));
  body.replaceText("{variableTwo}", reverseText(varTwo));
  body.replaceText("{variableThree}", reverseText(varThree));
}

Output:

Note: Image is for visibility only.

Sample Input: Sample Image Input

Sample Output: Sample Image Output

Reference:

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Lime Husky