cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Extract number from string

Say I have a string P001 in a Context variable, how can I get the number 001 and assign it back to that context variable?  


1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Extract number from string

Hi @Marini83 ,

Do you want to extract the Number value from a Text string?

 

Based on the needs that you mentioned, I think the Substitute function could achieve your needs. I have made a test on my side, please take a try with the following workaround:5.JPG

 

6.JPG

 

7.JPG

Set the OnSelect property of the "Initialize" button to following:

UpdateContext({ContextVar1: "P001"})

Set the OnSelect proeprty of the "Extract Number" button to following:

UpdateContext({ContextVar1: Substitute(ContextVar1, "P","")})    /* <-- On your side, you should take a try with this formula to achieve your needs */

Set the Text property of the Label to following:

"Current Context Variable value: " & ContextVar1

Please check the following GIF screenshot for more details:Test.gif

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Highlighted
Super User
Super User

Re: Extract number from string

Hi @Marini83 

Just to clarify, will your input value always be in the format - 1 alpha character followed by 3 numbers? Or will the preceding number of characters before the number variable?

 

 

Highlighted
Anonymous
Not applicable

Re: Extract number from string

Hi,

 

If the syntax is always PXXX, you can do like that :

Set(VAR, Value(Right(YourString,3)))

 

Best regards,

 

Louis

Highlighted
Frequent Visitor

Re: Extract number from string

Presumably yes , It should be in that format. 

Highlighted
Anonymous
Not applicable

Re: Extract number from string

@Marini83,

 

Then you can process as I explained, and put the code in the OnSelect property of a Button, for example.

 

BR,

 

Louis

Highlighted
Community Support
Community Support

Re: Extract number from string

Hi @Marini83 ,

Do you want to extract the Number value from a Text string?

 

Based on the needs that you mentioned, I think the Substitute function could achieve your needs. I have made a test on my side, please take a try with the following workaround:5.JPG

 

6.JPG

 

7.JPG

Set the OnSelect property of the "Initialize" button to following:

UpdateContext({ContextVar1: "P001"})

Set the OnSelect proeprty of the "Extract Number" button to following:

UpdateContext({ContextVar1: Substitute(ContextVar1, "P","")})    /* <-- On your side, you should take a try with this formula to achieve your needs */

Set the Text property of the Label to following:

"Current Context Variable value: " & ContextVar1

Please check the following GIF screenshot for more details:Test.gif

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Dual Super User III
Dual Super User III

Re: Extract number from string

@Marini83 

 

Assuming that the context variable is set to value as:
UpdateContext({VariableName:"P001"});
 
Can you try to use below expression to get only the number after the first Character? This first character could be anything, not just "P".
UpdateContext({VariableName: Mid(VariableName,2)})
MicrosoftTeams-image (171).png

 

Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!
 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,929)