Add spaces before and after a specific character

I would like to add spaces before and after the character " - " , I have a string like this : “745000-1”
And the desired output is : “745000 - 1”
How can I do that using Regex expressions or else ?

1 Like

Hey @Rooty

You can use String.Replace method. Like this:

Left Assign
Str_Result

Right Assign
Yourstring.replace(“-”," - ")

Check out this String Manipulation post:

Or you can use Regex like this:

Left Assign
Str_Result

Right Assign
system.Text.RegularExpressions.Regex.Replace(YourString,“-”," - ").ToString

Learn Regex through these links:

Cheers

Steve

1 Like

Thank you @Steven_McKeering

Your answer was really helpful, this was the solution for me :

Cordially,

Yeah I would recommend the String.Replace method also as its the simplest method for your sample.

You just need to be cautious of if there are other “-” in your samples. As they will be replaced/updated also (may not be a problem).

If that was the case I would use Regex :slight_smile:

Happy to assist you :blush:

Cheers

Steve

1 Like

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