Skip to main content

Notifications

Power Apps - Building Power Apps
Suggested answer

Divide text string into several pieces based on a date

Posted on by 147
Hi,
 
I have a long text string with comments that is built like this:
 
"2024-10-01
Blablablabla

2024-10-02
Blabla bla bla
 
etc."

Now I want to divide this string into pieces where the new strings start with the dates each time. The idea is to use Split and MatchAll, but I can't figure out how to combine these functions. Or is there any better ideas?

All ideas are welcome and appreciated!
  • Suggested answer
    ronaldwalcott Profile Picture
    ronaldwalcott 855 on at
    Divide text string into several pieces based on a date
    Something like this should work even though needs to be optimized. The example is created with a label and a button.
     
    Label1.Text set to 
    "2024-10-01 Blablablabla 2024-10-02 Blabla bla bla 2024-10-03 TestBlabla bla bla"
    "\d\d\d\d\-\d\d\-\d\d" is a regular expression representing the format of the date in your example
     
    The button OnSelect set to 
     
    UpdateContext({theStringLength: Len(Label1.Text)});
    
    ClearCollect(
        myIndexedTable,
        With(
            {
                data: ShowColumns( MatchAll(Label1.Text, "\d\d\d\d\-\d\d\-\d\d"),StartMatch)
                
            },
            AddColumns(
                RenameColumns(
                    Sequence(CountRows(data)),
                    Value,
                    Index
                ),
                StartString,
                Index(
                    data,
                    Index
                ).StartMatch
            )
        )
    );
    
    ClearCollect(mySearchTable, myIndexedTable);
    
    ClearCollect(
       myStringStartAndSize,
       AddColumns(
          myIndexedTable,
          strLength,
          With({
          getStringPosition:LookUp(mySearchTable,  Index = myIndexedTable[@Index] + 1, StartString)
          },
          If ( !IsBlank( getStringPosition)  , getStringPosition -  myIndexedTable[@StartString], theStringLength - myIndexedTable[@StartString] + 1 )
          )
       )
    ); 
    
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,246

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,884

Leaderboard