cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
PytByt
Level 8

How to separate text content inside a label into multiple text part

Hi all..

 

I want to know how i can devided a content text that inside a label text automatically into multiple text part.

 

For example:
text3.pngI have this value of label.text, and i want to divide it into 3 part

I want to divide it into 3 part, each part is separated with the number inside the bracket. (the number inside the bracket is not included into the devided part);

 

ie:

part1: 00884450005156 --> into label1.text
part2: 220228 --> into label2.text

part3: K1527906 --> into label3.text

 

Can i achieve this?
How?


Pleas help.

Thanks,

BR.

pytbyt

2 ACCEPTED SOLUTIONS

Accepted Solutions
Super User
Super User

Re: How to separate text content inside a label into multiple text part

@PytByt 

I am now back at a computer and was able to test a solution for you by placing the formulas below in the Text property of 3 separate label controls.  

 

1st Text: 00884450005156

Last(FirstN(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+"),2)).FullMatch

 

2nd Text: 220228

Last(FirstN(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+"),4)).FullMatch

 

3rd Text:  K1527906

Last(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+")).FullMatch

 

The MatchAll() function enables searching for patterns within a text string using regular expressions.  If you'd like to learn more about regular expressions and practice how to use them I suggest the website https://regexone.com/. I used it a few years ago myself and thought it was spectacular.

 

---

Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly.  If your thought the post was helpful please give it a "Thumbs Up."

 

 

View solution in original post

FernandoTC
Level: Powered On

Re: How to separate text content inside a label into multiple text part

Hi @PytByt 

Sorry I couldn't answer before.

 

As I don't know the workflow of your app I'll give you a full solution assuming you want to convert the string when pressing a button.

What we are going to achieve is to have a collection with the 3 numbers you want to obtain, one in each row.

 

  1. First, create a text input (TextInput1 in my example) where you are going to type the string to split when the app is running.

  2. Then, add a button with the following code in the on the Onselect property:
    Clear(_NumberCollection);
    ForAll(
        Split(
            TextInput1.Text,
            "("
        ),
        If(
            !IsBlank(Result),
            Collect(
                _NumberCollection,
                Right(
                    Result,
                    Len(Result) - Find(
                        ")",
                        Result
                    )
                )
            )
        )
    )
    How does this work? We are going to store the numbers into a collection called _NumberCollection. So first, we clear that collection so the numbers obtained in the previous run are deleted.

    When using the function forall() we are going to perform an action for each of the items of a table specified as the first argument of this function. In this case, this table is going to be the split function with the same syntax as I gave you in my first reply. This will create a table with 4 items, being the first empty and the other 3 the numbers you want to obtain but preceded by the numbers between brackets and ")".

    The second argument of the Forall() function is the action we want to perform. So, we want to add to the collection _NumberCollection the final numbers. To get rid of the blank entry created in the first split, we apply this action only if the result of the function split is not blank. And then, we Collect the final numbers by using the expression I gave you in my first reply.

    This gives us a Collection _NumberCollection with the three numbers you want to obtain. 
  3. If you want to refer to a number stored in this collection, you can use the following expressions:
    -For the first number: 
    First(_NumberCollection).Value
    -For the second number:
    Last(FirstN(_NumberCollection,2)).Value
    -For the third number:
    Last(_NumberCollection).Value
    I think this syntax speaks by itself.


Hope this solution is what you wanted, and don't hesitate to ask for more help.

 

Have a good day.

View solution in original post

23 REPLIES 23
Super User
Super User

Re: How to separate text content inside a label into multiple text part

@PytByt 

The simplest way to do it would be the MID function if your text string is fixed length and follows a consistent format.  Otherwise, you'll have to start looking at the SPLIT and MATCHALL functions. 

 

Part1

Mid("(01)00884450005156(17)220228(10)K1527906",5,14)

 

Part2

Mid("(01)00884450005156(17)220228(10)K1527906",23,6)

 

Part3

Mid("(01)00884450005156(17)220228(10)K1527906",33,7)

 

Let me know if the simple way works

 

---

Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly.  If your thought the post was helpful please give it a "Thumbs Up."

PytByt
Level 8

Re: How to separate text content inside a label into multiple text part

Hi @mdevaney 

This simpliest way is work perfectly. Thank you.

 

However, can you help me out with my text string is not fixed length format? 
I believe i would have to face the possibility that i have the not fixed length string format.

 

I still not familiar with the SPLIT and MATCHALL functions. 

I'm sorry if this troubled you a lot.

 

BR,

pytbyt

FernandoTC
Level: Powered On

Re: How to separate text content inside a label into multiple text part

Hi.

 

I have two solutions that you can apply in an scenario where the string lenght is variable either the numbers you want to extract, or the numbers in between the brackets (which you don't want to work with)

First solution consists in using Split, right and find. Your data shall be stored withing a collection or table:

  1. Create a collection or gallery and collect or set items property to:
    Split(
             "(01)00884450005156(17)220228(10)K1527906",
              "("
    )
    This will create a table with the following records:
    <Empty>
    01)00884450005156
    17)220228
    10)K1527906

    Note that there is an empty string in the first record as the split functions finds the first "(" at the beginning of the string.
  2. You can add a column (if you are working with a collection) or a label if you are doing it with a gallery using this expression:
    Right(
        ThisItem.Result,
        Len(ThisItem.Result) - Find(
            ")",
            ThisItem.Result
        )
    )
    This will select the x right characters of each sub-string where x is the length of that string minus the position of ")" in each string leaving you with the result. (Don't forget that the first entry is empty, so filter it or deal with it)

  3. This solution will work for any number of characters in each of the zones of the string:
    Captura1.PNGCaptura2.PNGCaptura.PNG

    Here are some examples with your particular text and others with variable lengths (this also work with a text to be splited in less or more sub-strings)

 

Hope this helps you! And if it does, don't forget to mark the question as solved.

Super User
Super User

Re: How to separate text content inside a label into multiple text part

I’m not by a PC at the moment but, in general, you’d use MATCHALL to extract each set of numbers not containing brackets into a single column table. The result would be a 6 item Table. You’d then use the FirstN and LastN formulas to return the 2nd, 4th and 6th items (ie your 1st, 2nd and 3rd sections of the serial number).

MatchAll requires you to learn pattern matching. There is some more info in the documentation. But it’s easier just to search Google for “regex pattern for not containing brackets”
PytByt
Level 8

Re: How to separate text content inside a label into multiple text part

Hi @FernandoTC 

 

Thank you for your reply and solution.

 

Could you please share more details about how to create the collection? and i'm willing to use it in a label for the split result.

I think your solution is great approach for my case, but i havent figure it out completely for my lack of powerapps abilities.

 

I'm sorry if this troubled you a lot.

 

Thanks,
BR. 

pytbyt

 

PytByt
Level 8

Re: How to separate text content inside a label into multiple text part

Hi @mdevaney 

Sorry for the trouble, 

But i get more confuse.. >_<

I hope you could help me more.

 

I'm truly sorry for being such a noob in powerapps.

 

BR.

pytbyt

Super User
Super User

Re: How to separate text content inside a label into multiple text part

Hi there. I’ve given your question an attempt below but there’s no way to check my work because I am not at a PC. You can give the formulas I provided a try but I can’t validate they work until I can get on a PC. By all means give them a try though.

1st Text:

LastN(FirstN(MatchAll(“(01)00884450005156(17)220228(10)K1527906",”^[a-zA-Z0-9]*$”),2),1).Result

2nd Text:

LastN(FirstN(MatchAll(“(01)00884450005156(17)220228(10)K1527906",”^[a-zA-Z0-9]*$”),4),1).Result

3rd Text:

LastN(MatchAll(“(01)00884450005156(17)220228(10)K1527906",”^[a-zA-Z0-9]*$”),1).Result
PytByt
Level 8

Re: How to separate text content inside a label into multiple text part

Hi @mdevaney 

 

Thank you for you reply.. 

I dont want to troubled you, but i get invalid argument type error. Expecting text value instead

What the error means? and what should i do?

I hope you can get on you PC soon, and i imagine that you are on a travel perhaps? save trip mate.

 

Cant wait to get the right solution from you.

 

Cheers,

pytbyt

Super User
Super User

Re: How to separate text content inside a label into multiple text part

@PytByt 

I am now back at a computer and was able to test a solution for you by placing the formulas below in the Text property of 3 separate label controls.  

 

1st Text: 00884450005156

Last(FirstN(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+"),2)).FullMatch

 

2nd Text: 220228

Last(FirstN(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+"),4)).FullMatch

 

3rd Text:  K1527906

Last(MatchAll("(01)00884450005156(17)220228(10)K1527906","\w+")).FullMatch

 

The MatchAll() function enables searching for patterns within a text string using regular expressions.  If you'd like to learn more about regular expressions and practice how to use them I suggest the website https://regexone.com/. I used it a few years ago myself and thought it was spectacular.

 

---

Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly.  If your thought the post was helpful please give it a "Thumbs Up."

 

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,216)