How to add hyphens to a number (to use it to search a DB table)

Hello, marvelous gurus. I have a 13-digit number and I want to add hyphens to it.

example input: 9585022686126
desired output: 958-5-0226-8612-6
(number groupings: 3, 1, 4, 4, 1)

I'm thinking "split" would do this, but I'm not sure how since there is no current dividing character.

The ultimate goal is to pull these digits from a website (I've done that successfully) and then use them to select a row in a data blaze table, wherein those numbers have hyphens. So I'm assuming I need to add the hyphens first before I can use this as a "WHERE" command in the dbselect, although I'd be happy to be wrong there!

If the values have hyphens in the DB table, they'll need hyphens in the WHERE clause if you're trying to match based on them.

These text functions will help make this possible. Here's an example -- not sure how you're getting the initial input, but this can be modified to accommodate any input source.

{formtext: default=9585022686126; name=input}

{=concat(left(input, 3), "-", substring(input, 4, 1), "-", substring(input, 5, 4), "-", substring(input, 9, 4), "-", right(input, 1))}

2 Likes

Ah yes, concatenate! Thank you. It works! Happy dance!

I have no coding background and am learning it all because it's so satisfying to make my snippets more powerful, so I really appreciate y'alls responsiveness in this forum.

1 Like