How to trim the spaces in Word Document when replacing the text

Hi Team,

I have a scenario where i need to trim the spaces in between the paragraphs based on the values present.
Original Word File:

When i replace the 2 values with text,other 8 values spaces needs to be trim.
currently am getting like below:


Appreciate your help! @HarrisonJard @lakshman @PalaniyappanOriginal File.docx (12.4 KB)

Hi @HarrisonJard,

Thank you for your response.
I am performing this task using UIpath,attached my work flow.
Trim Spaces.xaml (6.4 KB)

Appreciate your help @HarrisonJard


Can anyone help me on this requirement.

@HarrisonJard, the replace activity is making things hard to work with, especially for what you are trying to do.

Instead, I used assign activity and I used something like this:

To replace strings:

To Remove all blank newlines:

Here is an Example: Trim Spaces.xaml (8.8 KB)

1 Like

Hi @SenzoD @HarrisonJard,

I have used your xaml to trim the places,but the problem i am facing is when i use append text to paste the trim data ,it copying total data to same file again.
-I want to replace the existing data here(Overide) .

Can we trim data only specific area in word file?Trim Spaces (1).xaml (8.9 KB)

@RajeshT, create a new file, or just send hotkey to that file use ctrl + a to select everything, and then send another hotkey with backspace or delete to clear everything on the file then use the set to clipboard activity and then hotkey with ctrl + v to paste the data into the file.

1 Like

Hi @SenzoD,

Thank you so much for your response.
Can you able to help me to trim only highligted part in word file.
Appreciate your help.Original File_After Replace text.docx (19.1 KB)

1 Like

@RajeshT, i will fininsh work within an hour and i will do it

1 Like

@RajeshT, i cannot access my laptop right now, but i wanted to try something, please try it and let me know if it works

use a replace activity right underneath the message box activity, in the search for type in “WordText” and in the replace with type in “TrimWhiteSpace”, make sure the replace activity is inside the word scope.

i am assuming you have not changed my workflow, and the above variables are still valid. Please let me know if that works.

1 Like

Hi @SenzoD,

I have tried with the solution you have provided,but not able to get the proper result.
Appreciate your help.

1 Like