Changing a specific digit in a number value

Is it possible to change a specific digit in a number value? For example I’ve got the number 001 and would like it to change with a workflow to 901. The initial value will always be 9 as well. so could be 351 but changes to 951.

Thanks!

This is going to sound really convoluted but:
Add Arbitrary Text:converted to number
Inside it type a 9 manually then insert dynamic data right after it:
[number]:format as Number:extract with Regex (put a single period .):from item #2:joined with Arbitrary Text (Insert dynamic data but don’t actually pick anything)

:rofl:

Basically takes off the first character, puts a 9 in front then converts the whole thing back to a number

1 Like

Oh boy that does look exciting to say the least :rofl:

Will give it a go soon thanks for the advice!

1 Like

There might be a more math expression way of doing it, like if you know its always starts with 300-something you can just add 600 to the number but doesn’t sound like that is the case

Unfortunately not as the number could be anything from 000 to 999 where the workflow wouldn’t even trigger if it has its first value as a 9.

I thought of a different way of my 1st reply:
Arbitrary text:converted to number
Inside that:
Manually type 9 then insert dynamic data: [number]:format as Number:truncated from end to [number]:format as Number:# of characters -1

:joy:

Hey Bud,

Apologies as I had to fix other things with the app to get to your solution first. I am currently stuck on how to get to the Arbitrary text. The data type is a text as it does involve letters before the actual numbers that I need to change.

Shell ID would be what were changing. E.g.

Shell ID: 635x069x136x001 where the 001 at the end is where we would change it to 901.

Thanks again for your help!

Update:

This is where I got to so far…

Try this:
Shell ID = This Shell ID: find & replace
Then make sure ‘use a regex pattern’ box is clicked. In the ‘text to find’ box type this:
\d(?=\d\d$)
and in the ‘replace by’ box type:
9
Let me know if that works or if you need further clarification

1 Like

Wow that seems to work perfect,

If I could ask what does the "\d(?=\d\d$) do? and for ‘use a regex pattern’?
Thank you so much for your help appreciate it!

If you didn’t have the ‘use a regex pattern’ box checked, bubble would have looked for the exact sequence of characters ‘\d(?=\d\d$)’ in your text and not found it. When evaluating as a regex, those characters take on meaning:

d by itself would have looked for every letter ‘d’ and replaced it with ‘9’.

\d when you add the ‘\’ it says to look for every digit (0-9)

(?=) for everything that matches what comes after the ‘=’, don’t include it in the result, but look ahead (in front) of ‘(?=)’ to find what you want included in the result. In this case \d(?=\d\d) you are looking for the number that comes in front of 2 numbers. If we had left it at that, it would have found every place 3 numbers were in a row and given you the first number of each of those matches (and repaced it with ‘9’) When you add the ‘$’ it says that the ‘$’ represents the end of the text, so only one set of 3 numbers in a row is at the very end.

It’s always best to test these expressions to confirm how they are read.

A couple other things to note:
If you were looking to extract a number from a number type, I assume you would need to convert the number to a text (:format as…) evaluate, and then convert it back to a number (I don’t think bubble does this automatically, but haven’t checked).
If you are using ‘:extract with Regex’ (outside of ‘find & replace’) it will return a list, and even if there is only one result, you may need to select ‘:first item’

1 Like

Thank you for this information, appreciate your time explaining it and understand it a lot better.