web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Remove last character ...
Power Apps
Answered

Remove last character in string IF the last character is a specific character like ; or |

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

In my form I have a couple of text inputs that add to a collection. On input, it separates each item in the collection with |.

 

It then saves the collection to a SharePoint field and it will look something like

 

1;test1;no;yes|2;test2;no;yes|3;test3;yes;yes|4;test4;no;no|

 

I'm displaying the collection in a gallery by splitting it at |. The problem is on the last | it assumes there's another item after it, but there isn't, that's support to be the end.

 

I used Left(varStringofCollection, len(varStringofCollection) -1) to remove the ending | and that works.

 

But the problem I noticed is that some users will open the item multiple times before saving it and instead of it opening as 

1;test1;no;yes|2;test2;no;yes|3;test3;yes;yes|4;test4;no;no

 

It will open as
1;test1;no;yes|2;test2;no;yes|3;test3;yes;yes|4;tes

 

basically removing parts of the collection. I want to only remove the last | from the string. If it's not there, then do nothing.

 

Any ideas?

 

Thanks!

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @Anonymous 
    Assuming you have a string value like this:

    Set(myText, "1;test1;no;yes|2;test2;no;yes|3;test3;yes;yes|4;test4;no;no|")

     

    We can conditionally remove the last item if it is a pipe |  or otherwise do nothing.

    Set(
     With(
     {varText: "1;test1;no;yes|2;test2;no;yes|3;test3;yes;yes|4;test4;no;no|"},
     If(Right(varText,1)="|",
     Left(varText, Len(varText-1)),
     varText
     )
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Awesome! Thank you for the quick reply.

     

    What is the With doing? Have never used that before.

     

    Also, the vartext would be pulled from a SP list. So mine would look something like

     

    Set(
     With(
     {varMonitorPressureAllItems: ThisItem.MonitorPointPressure},
     If(Right(varMonitorPressureAllItems,1)="|",
     Left(varMonitorPressureAllItems, Len(varMonitorPressureAllItems-1)),
     varMonitorPressureAllItems
     )
    )

    Getting errors though. Is the With necessary or can I just the If Right? 

  • mdevaney Profile Picture
    29,991 Moderator on at

    @Anonymous 
    WITH allows you to store a variable for a specific section of code and then immediately deletes it when the function is complete.  I like to use it because my code will only make 1 call to SharePoint instead of up-to 3.

     

    What errors are you getting.  Please supply the full error message and a screenshot of your code. 

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up." 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    This is the call that happens on select of the gallery button. If I input yours the whole thing turns red. I may now be putting it in the right place?

    Set(
     varWAPItem,
     ThisItem
    );
    If(
     IsBlank(varWAPItem.MonitorPointPressure),
     Clear(colMeasurePointPressure),
     Set(
     varMonitorPressureAllItems,
     varWAPItem.MonitorPointPressure
     );
     ForAll(
     Split(
     varMonitorPressureAllItems,
     "|"
     ),
     Collect(
     colMeasurePointPressure,
     {
     ppLocationItem: PlainText(
     Last(
     FirstN(
     Split(
     Result,
     ";"
     ).Result,
     1
     ).Result
     ).Result
     ),
     ppPSIItem: PlainText(
     Last(
     FirstN(
     Split(
     Result,
     ";"
     ).Result,
     2
     ).Result
     ).Result
     )
     }
     )
     )
    );

    I think there's some missing syntax, it doesnt like the whole thing.

    If(
     IsBlank(varWAPItem.MonitorPointPressure),
     Clear(colMeasurePointPressure),
     Set(
     varMonitorPressureAllItems,
     varWAPItem.MonitorPointPressure
     );
     Set(
     With(
     {varMonitorPressureAllItems: ThisItem.MonitorPointPressure},
     If(Right(varMonitorPressureAllItems,1)="|",
     Left(varMonitorPressureAllItems, Len(varMonitorPressureAllItems-1)),
     varMonitorPressureAllItems
     )
    );
     ForAll(
     Split(
     varMonitorPressureAllItems,
     "|"
     ),

     

     

  • mdevaney Profile Picture
    29,991 Moderator on at

    @Anonymous 
    Sorry, but that section of wavy code is a little much for me to parse.  I don't necessarily understand what's going on here.  Simplifying the code/question might help.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Verified answer
    Community Power Platform Member Profile Picture
    Microsoft Employee on at

    FYI I got it to work but only by removing the with. Thanks for the help

     

    Set(
     varMonitorPressureAllItems,
     If(
     Right(
     varMonitorPressureAllItems,
     1
     ) = "|",
     Left(
     varMonitorPressureAllItems,
     Len(varMonitorPressureAllItems) - 1
     ),
     varMonitorPressureAllItems
     )
     );

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard