replace only the first digit
Question
Hi everyone! Please tell me how to replace only the first digit in a set of numbers, for example, replace the first 5 out of 55555. I tried to use Replace, but all 5 change. Thanks

Use below forge comments 

https://www.outsystems.com/forge/component/2007/text-and-html-processing/

Hi KeenyS,

Could you please try this into an expression? The string function substr will pull the first character from the passed string and if the first character matches with your replace character it will replace else it will show the original only.

Replace(Substr("55555", 0, 1), "5", "7")

Thanks & Kind Regards,

Sachin

Hi Kenny,

I tried to do this myself. I have 2 assign statements that will create substrings and replace the values. 

 To do this I have 3 local variables: OriginalNumber, ReplaceFirstNumber and TempSecondary.

First assign ^ 

Second assign ^  

TextToInteger(Concat(Replace(Substr(OriginalNumber,0,1),Substr(OriginalNumber,0,1),ReplaceFirstNumber),TempSecondary))

This will replace the first digit of original number with the new number and then concat the changed number with thre rest of original stored in tempsecondary. 

I noticed that while using the logic of Sachin all the numbers changed if you make that dynamic since the logic will search for 5 and replace all instances of 5.

Max de Groot, @KennyS 19 Keep it simple.

You only need to replace the first digit, so try this:

Create a new var to hold the new value and then apply the expression that is on the screenshot:


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.