Obtain first values from text

Is there a way I can get the first number from a text sentence?

Right now I have a text that can be either 10% of discount or can be only 5%, is there a funtion that allows me to obtain these numbers and exclude the following characters?

If the values you are obtaining are "10%" and "5%" you can use substring function: 

Substr(Text,Start(zero-based),lenght)

Have you considered storing those values into static entities with an attribute named "DiscountText" and another attribute of integer type that stores 10 and 5?

Denis Portillo wrote:

If the values you are obtaining are "10%" and "5%" you can use substring function: 

Substr(Text,Start(zero-based),lenght)

Have you considered storing those values into static entities with an attribute named "DiscountText" and another attribute of integer type that stores 10 and 5?


I'm afraid it´s not like that, I have an entire sentence of dinamic values such as 35% of perfum descount or just 20%, from an entire sentence I want to remove the first numbers.

In order to have: 35, 20...

So, what if you use substring function but taking away the "%" symbol?

TextToInteger(Trim(replace (FullTextReceived,"%","")))

Don't forget to validate with TextToIntegerValidate

lucas ferreira wrote:


Denis Portillo wrote:

If the values you are obtaining are "10%" and "5%" you can use substring function: 

Substr(Text,Start(zero-based),lenght)

Have you considered storing those values into static entities with an attribute named "DiscountText" and another attribute of integer type that stores 10 and 5?


I'm afraid it´s not like that, I have an entire sentence of dinamic values such as 35% of perfum descount or just 20%, from an entire sentence I want to remove the first numbers.

In order to have: 35, 20...



Hi Lucas,

More examples for help you:

Regards.


Hi, lucas.

You might want to take a look at using a regular expression.

Regex_Search server action from the Text extension allows you to work with regular expressions within OutSystems.


The pattern bellow will match every number followed by a % sign in a string.

[0-9]+(?=%)

If you want to match the first number you have on your string, just replace with the following pattern:

[0-9]+

You can test your expressions here




Best,

Tiago

HI Lucas,

As Tiago shared, you can use Regex_Search action from Text extension if you want to get any first occurance of consucative numbers in your text you can even use below regix with this method:

It will return any fust occurance of numbers in any text.