Skip to main content

Notifications

Community site session details

Community site session details

Session Id : j2QWAZcRVLQ+RuhE1YjWvC
Power Automate - Building Flows
Answered

Trim function not deleting whitespace

Like (1) ShareShare
ReportReport
Posted on 30 Jan 2024 20:32:42 by 17

I'm trying to delete whitespace in a string using this expression

 

replace(Trim(triggerOutputs()?['body/Title']),' ','.')

 

This is for a SharePoint triggered flow and the title was renamed to "Full legal name" in the associated list. It trims the ends just fine. But according to this article (https://learn.microsoft.com/en-us/power-platform/power-fx/reference/function-trim), trim should eliminate the extra spaces in the string (it even shows it in one of their examples) as opposed to TrimEnds. And yes, once the string is trimmed, I need to replace the space with a period. I'm using this to generate what their email address will be for later on in the flow. 

 

Currently, if their name comes in as "Desaad  Joker   ", it will trim off the whitespace at the ends and replace the two spaces in the string with periods "Desaad..Joker". What am I missing?

  • Suggested answer
    David_MA Profile Picture
    10,858 Super User 2025 Season 1 on 08 Aug 2024 at 15:55:43
    Trim function not deleting whitespace
    -----
  • AnthonyAmador Profile Picture
    2,544 Super User 2025 Season 1 on 08 Aug 2024 at 15:29:49
    Trim function not deleting whitespace
    Hi @DavidMelton

    Unfortunately the trim function doesn't remove the white spaces between words, from documentation the Trim function removes all spaces from a string of text except for single spaces between words.

    What I do to remove the whitespaces is the function replace(), replace ' Hello World ! ' with your variable. 

    replace(' Hello World ! ', ' ', '')
     
    Hope this helps. 
    Anthony. 
  • Joseff Profile Picture
    37 on 08 Aug 2024 at 14:59:27
    Trim function not deleting whitespace
    Hey David,

    I usually go for something like
     
    trim(replace(replace(replace(triggerBody()?['text'],' ',' _  '),'   _',''),'_  ',''))

    Where triggerBody()?[
    'text'] is the text I want to remove extra spaces from
  • Verified answer
    DaveMelton Profile Picture
    17 on 30 Jan 2024 at 20:39:09
    Re: Trim function not deleting whitespace

    I think I just answered my own question. The whitespace trim only works that way in Power Apps. Not Power Automate. 

     

    Hey, Microsoft! Can we get some consistency here?

     

    For the rest of you, is there a standard way of removing whitespace? (and yes, I still need a single space between words)

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 97

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 70 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 48 Super User 2025 Season 1

Overall leaderboard