How to Replace Spaces with Underscores in String using Power Automate?

When you upload a file with spaces into a SharePoint document library, the file URL will be created, where the spaces are stored as %20.

For example: If there is a file ‘Guidelines for Project Meet Ups’-> the URL will be saved as ‘Guidelines%20for%20Project%20Meet%20Ups.

You can replace the file name with underscores, so that the URL generated is clear and avoids the %20.

In this tutorial, I will explain how to replace a string containing spaces with underscores using Power Automate.

Replace Spaces with Underscore from a String in Power Automate

To explain this, I will take a text string that represents a file name: Stakeholder Meeting Notes 2025 06 25.docx.

I need to replace the spaces with underscores in the string mentioned above, so that the output should be like: Stakeholder_Meeting_Notes_2025_06_25.docx.

To achieve this, you can use the replace() function in Power Automate.

Check out the steps below:

  1. Create an Instant cloud flow in Power Automate. If you are new to Power Automate, check out how to create a Power Automate Instant cloud flow.
  2. Then, initialize the text string variable so that the value can be used in the following actions. Add an ‘Initialize variable‘ action. Set the parameters.
    • Name: Provide a name for a variable.
    • Type: Select the type as ‘String’.
    • Value: Take the string value here.
Power Automate replace spaces with under scores
  1. Next to that, add a ‘Compose‘ action to replace the string having spaces with an underscore. Provide the below expression in the Inputs parameter.
    • Inputs: Insert the expression given below.
replace(variables('VarFileName'),' ','_')
Replace spaces with Underscores Power Automate

Save the actions to the flow by clicking on the Save icon. Then, test the flow manually by clicking on the Runflow button.

Output:

Replace spaces with Underscores in String Power Automate

This way, you can replace spaces in a string with an underscore using the Power Automate replace() expression.

I hope you now have an idea about how to replace spaces with underscores in a string using Power Automate. Leave your feedback or suggestions in the comment section!

You may also like the following tutorials:

>
SPGUIDES.ACADEMY
LEARN. BUILD. TRANSFORM.
â–¶ Live FREE Webinar

Build an AI-Powered
Invoice Processing
App

Learn how to build an intelligent invoice processing solution using:

S SharePoint
â—† Power Apps
➤ Power Automate
✦ Copilot Studio
PDF INVOICE
→
AI
→
◆ ➤ S
From Invoice
to Insights
Invoice Processing ↑ Upload Invoice
INVOICE
TOTAL $1,950.00
Extracted Information
Vendor Name Contoso Ltd.
Invoice Number INV-1001
Invoice Date 09/05/2026
Due Date 09/25/2026
Line Items
Laptop 2 $1,600.00
Mouse 5 $150.00
✓ Save to SharePoint
â–£
DATE 22nd September 2026
â—·
TIME 10:00 AM EST 7:30 PM IST
⌛
DURATION 60 Minutes
🚀 Save Your Free Seat ›

Live Webinar

SharePoint Integration Power Apps Form With Repeating Table [Invoice Management System]

Learn how to build a real-world Invoice Management System using a SharePoint Integration Power Apps Form with a repeating table—supporting multiple invoice line items.

📅 2nd September 2026 – 10:00 AM EST | 7:30 PM IST

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…