How to remove extra space after hyphen in a string

Hi Guys,

I’m using find children to get the Ui Elements from a dropdown, after which I use get atributes to get the innertext.

But there is a bit of an issue, the innertext is returned as “Practice - Lab - Medical”
Output: “Practice - Lab - Medical”
Expected: “Practice - Lab - Medical”

In output there is extra space before Lab and Medical, I want to remove that extra space

I want to one shown in expected value, as it is the one present in the dropdown.
Any help is much appreciated, thanks.

Hi @Aazmaanahmed_Khan

There is no difference between the output and the expected mentioned by you

But if you wanted to remove the outerpsaces then use the .trim to remove outer spaces

variable.tostring.trim

Regards

@Aazmaanahmed_Khan Hi, I am not able to find any difference in your Example and expected output

Hi,

Yes I have tried that, I had edited the post.

There is extra space before Lab and Medical , I want to try removing that.

Hi,

Yes I have tried that, I had edited the post.

There is extra space before Lab and Medical , I want to try removing that.

Hi @Aazmaanahmed_Khan

  1. After using the “Get Attributes” activity to retrieve the “innertext”, add an “Assign” activity to store the retrieved value in a string variable. Let’s assume you have a variable called innerTextValue to store the value.
  2. Add another “Assign” activity to trim the innerTextValue. Set the following expression:

innerTextValue = innerTextValue.Trim()

Hope it helps!!

@Aazmaanahmed_Khan
assign the output value to a variable and use the below mentioned syntax for that variable

variable.replace(" - ","-").tostring

Regards

@Aazmaanahmed_Khan
@Aazmaanahmed_Khan
Use One Assign Activity:
Left side Put StringType Variable
Right side put this Expression:

System.Text.RegularExpressions.Regex.Replace(inputString, "\s*-\s*", "-")

It will delete all spaces which are available before and after hypon. Its generic one when you don’t know how many number of spaces are Coming. Simple replace handle only when you know the number of spaces and its fixed for all cases.

Hi @Aazmaanahmed_Khan

Use this below syntax:

input = “Practice - Lab - Medical”
input.Replace(" - “,”-").Trim

Hope it helps!!
Regards,

Hi @Aazmaanahmed_Khan

Try this

YourVariable.Replace(" - “,”-").ToString

I hope it helps!!

Hi,
I guess what you want to express is as the following.

Output:    "Practice -  Lab -  Medical"
Expected:  "Practice - Lab - Medical"

If so, can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"  +"," ")

Regards,

@Aazmaanahmed_Khan
Check This one:
Example:

Arslan -  Imtiaz-> After hypon 2 spaces:

@Aazmaanahmed_Khan
Here in yellow part you can put every thing whatever you want:

Hi @Aazmaanahmed_Khan

Try to replace the space like this

- Assign -> Variable = “Practice -  Lab - Medical”
- Assign -> Variable = Variable.replace("  "," ")

In replace in first double quotes give the double space and in second double quotes give single space.
When you use this it will replace the double space to single space.

Hope it helps!!

@Aazmaanahmed_Khan

Welcome to the community

To make it clear if there is more than one space and if you want to have only single space in place of that then use the below expression

This has to be used in assign activity and lets say the string is stored in a variable str then

Str = System.Text.RegularExpressions.Regex.Replace(" +"," ")

Cheers

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