Do I need an escape character? Make is deleting the + symbol from replace command

:bullseye: What is your goal?

remove +44 from phone number

:thinking: What is the problem & what have you tried?

Make removes the plus

{{replace(2.phone; +44; emptystring)}}

becomes:

{{replace(2.phone; 44; emptystring)}}

as soon as I save it.

Can anyone suggest a workaround please?

{{replace(replace(2.phone; “+”; emptystring); 44; emptystring)}}

works - I won’t mark this as a solution as it seems very clunky.

Yeah + is a special symbol that you need to escape.

Or you can use the parse a phone number module and get the phone number from whatever format to the desired one.

How do you escape it?

Also why is the behaiviour inconsistent?

You can use toString() to force the literal + to be used instead of the special symbol.

{{replace(2.phone; toString("+")44; emptystring)}}

Thanks, is there not an official / proper / non fudged way to do this?

Yeah no, that’s the proper way at the moment. If you need to use the actual + char and not the special one, you need to use toString to change it.

So is there no difference between using the + symbol on the keyboard and the operators shown below? I kind of assumed that was the whole point of having these.

image

Oh no those work just fine. Those are math related operations.

The + sign is used to merge two text strings together in programing. This is why it breaks when you try it as part of something bigger.

So 4{{+}}4 is the math operation and equals 8. Where 4+4 is the string operation and equals 44. Hope that makes sense.

And if you need the actual string + then you need to put it in a toString function to use it. So if you need the literal 4+4 to appear then you need 4toString(+)4 in the variable.

I’ve also noticed that the + operator (the green one above) sometimes - inconsistently - treats the input as a string and joins them together instead of adding them.

Check your inputs. Most likely one of the numbers you are mapping is a string type variable and not number. In such cases add a parseNumber() function to force it.