Skip to main content
Best answer

Remove last 3 digits from a string

  • August 25, 2022
  • 4 replies
  • 1133 views

I’m setting up a logic sequence that takes any UK postcode and removes the final 3 characters and returns the remaining characters.

e.g.

B48OP becomes B4

B755UG becomes B75

and WV125ET becomes WV12

The postcode string could be 5, 6 or 7 characters long - in each case I want to remove the final 3 characters and return the remaining characters as above. I’ve already created steps to remove spaces and make upper case - it’s just this final bit I can’t figure out.

Any ideas?

Best answer by Troy Tessalone

@Hyde 

Try .slice(0,-3);

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • August 25, 2022

  • Author
  • Beginner
  • August 25, 2022

Hi Troy, thanks for this!

Ok, so I’ve followed that and used the following code to slice off the final 3 characters from the testing value “PR26QY”

 

let Text = inputData.Text;

let Text1 = Text.slice(-3);

output = [{Text1}];

 

But then it’s the final 3 characters “6QY” that are returned in the output and not the initial string which I need.

Can I use some code to remove the above output from the initial string to leave the remaining characters? Something like the following:

Output = [{Text} minus {Text1}]

?


Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • Answer
  • August 25, 2022

@Hyde 

Try .slice(0,-3);


  • Author
  • Beginner
  • August 25, 2022

That’s worked perfectly, thanks again for the help!