When working with Power Automate, it’s common to encounter scenarios where you need to manipulate text data—such as removing unwanted spaces—before further processing it. Whether you’re concatenating fields or dealing with user input the unnecessary internal spaces can cause issues like inconsistent formatting or errors in systems. so in this blog post, we will learn how to remove all spaces in string and format the text data.
Remove All spaces from string in PowerAutomate
In my scenario, I am using Power Automate to concatenate three fields—first name, second name (first character only), and last name—into a single string. However, after performing the concatenation, I noticed that extra spaces are still present at the beginning or throughout the result.
If you want to remove all spaces from the concatenated result (including spaces between words), you can use the replace()
function in Power Automate to replace ‘ ‘, ”.
In this expression:
concat()
is used to combine the three fields (cr52c_firstname
,cr52c_secondname
,cr52c_lastname
).replace()
removes all spaces (' '
) from the concatenated result.
replace(concat(items('Apply_to_each')?['cr52c_firstname'], substring(items('Apply_to_each')?['cr52c_secondname'],0,1), items('Apply_to_each')?['cr52c_lastname']), ' ', '')
But I noticed while this works for removing all spaces, it doesn’t address the leading and trailing spaces in individual fields before concatenation.
A more efficient approach would be to trim the individual fields before concatenating them. This ensures that any leading or trailing spaces are removed before the string is joined together.
Power Automate provides a built-in function, trim()
, which removes leading and trailing spaces from text.
replace(concat(trim(items('Apply_to_each')?['cr52c_firstname']), trim(substring(items('Apply_to_each')?['cr52c_secondname'],0,1)), trim(items('Apply_to_each')?['cr52c_lastname'])), ' ', '')
Conclusion
In Power Automate, spaces can be a tricky issue, especially when dealing with concatenation. By using the trim()
function effectively on each field or the concatenated result, you can clean up unwanted spaces and ensure your output is formatted correctly. The replace()
function is useful if you need to remove all spaces, but be cautious, as it will remove internal spaces as well, which might not always be the desired behavior.
See Also
- How To Use Pdf Function In PowerApps?
- Working With PowerApps Nested Gallery Control
- How Power Automate Create Excel Table Dynamically? | Power Automate
- How To Make A Csv File Utf-8 Encoded? | Power Automate
- How To Format Text In PowerApps? PowerApps Convert Text To Other Data Types
- Alternate Row Color In Gallery PowerApps: Simplest Way
- Check If PowerApps Contains Substring
- PowerApps If Statement And Nested If With Example
- Model Driven App With SharePoint Data Source
- PowerApps Get Day Of Week Date
Join us
- Subscribe Power Platform Geeks.