Add a space when bracket is availabe in a text

Hello friends,

I am running a project to extract specific text from a long string, it is working fine but I am facing a problem with few instances which contains brackets “( )” and there is no space between the previous word(s) and the openning bracket. For example,

Driver(Heavy Vehicle)
Team Leader(IT)

I need to insert a space before the openning bracket, to result the following:

Driver (Heavy Vehicle)
Team Leader (IT)

Not sure of Regex can help, or Concatinate function, need your help please.

Thanks

@Anwar_Mirza

You can use a replace

Str.Replace("("," (")

This should do it

Cheers

Hi @Anwar_Mirza

You can do String Manipulations for this,

- Assign -> Input = "Driver(Heavy Vehicle)"
- Assign -> Output = Input.Replace("("," (")

Check the below workflow for better understanding,

Hope it helps!!

A defensive Approach inserting only when Space is missing

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Hi Anwar
you can try this approach
Text = “Driver(Heavy Vehicle) Team Leader(IT)”
Regex= System.Text.RegularExpressions.Regex.Replace(Text, “(\S)(”, “$1 (”)

Regards
Hari

Thanks Anil, I tried it but this will also add a space for those instances which already have a space, I am gonna have double space. Is there a way to check if a space is already available befoe implementing the replace function?

@Anwar_Mirza

Then use this regex replace

System.Text.RegularExpressions.Regex.Replace(str," *\("," (")

Cheers

Thank you for your time, your solution is similar to Anil above, plz see my response to him. This solution will add unnecessary space to the cases where there is a space already. Can we check if there is a space availabe first befre taking the action?

1 Like

This is great Anil, IT WORKED :wink:

1 Like

Thans for your efforts dear, appreiated.

@Anwar_Mirza

Glad it helped

Happy Automation

Cheers

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.