Home > OS >  \ Operator not getting included in the SETFORMULA
\ Operator not getting included in the SETFORMULA

Time:12-29

I am executing an apps script which sets a formula in a cell as below

var a16_range = a4_range.getA1Notation();
formula_5 = `=INDEX(MAX(LEN(IFERROR(REGEXEXTRACT(TO_TEXT(${a16_range}),"(\.. )")*1))-2))`;
var a17_range = a1_range.offset(0,3);
a17_range.setFormula(formula_5);

after executing the cell with range a17_range is inserted as below

=INDEX(MAX(LEN(IFERROR(REGEXEXTRACT(TO_TEXT(K43:P57),"(.. )")*1))-2))

without the \. I dont know why and not able to figure out why does it not capture the \ while setting the formula

Please advise.

CodePudding user response:

The character \ in Javascript (within a string context) is a special symbol for signaling that the next char should be literal.

As mentioned by the user @Heiko Theißen in the comments above, in order to literally include the backslash char in a string, you must escape this special character by doubling it (\\).

Please refer to the Escape Character section in this page for more information.

  • Related