Rooty
(Mohamed El Ouehabi)
July 25, 2022, 9:46pm
1
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:
Hi,
if you are a beginner in the world of automation and would like to know how you can manipulate text based on the solutions available in the VB.NET code and using REGEX (regular expressions) then you are in the right place.
In the topic below, you will learn how to easily extract data from any part of the search text using various methods.
The topic includes solution examples with descriptions and graphics to better understand the topic for functions such as:
Split
Substring
Left
Right
R…
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:
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
Cheers
Steve
1 Like
Rooty
(Mohamed El Ouehabi)
July 25, 2022, 10:59pm
3
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
Happy to assist you
Cheers
Steve
1 Like
system
(system)
Closed
July 28, 2022, 11:12pm
5
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.